Find the number of 2 digit numbers whose digit sum is a perfect square.
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
damn. I missed the 1
It doesn't change anything, but shouldn't your combined inequality read 1<=a+b not 0<=...?
The required set is
{10, 13, 18, 22, 27, 31, 36, 40, 45, 54, 63, 72, 79, 81, 88, 90, 97}
Here is some Mathematica Code:
Select[Range[10, 99],
MemberQ[{1, 4, 9, 16}, Total[IntegerDigits[#]]] &]
It is entirey based on casework as you said :)
What else can I expect from you other than a piece of code?
Log in to reply
Hmm, this was an ugly case work question.
Even more ugly is to try all the cases from case 10 to case 99 individually checking if they meet your criteria. This is what my code does.
A smarter method is to notice that the sum of digits of a teo digit number wont exceed 18 and hence if its digit sum is a perfect square, it would be an element of {1,4,9,16}. Now, write down all the integer partitions of these numbers into two integers and calculate all its permutations.
How timε-consuming! You wanted me to do that by hand?
Log in to reply
Well its not very time consuming
First you have to the no of two digit numbers having digit sum 1 there is only one possibility 10
Next find the no of two digit numbers having digit sum 4 there are 4 numbers-13,22,31,40
Then find the no of two digit numbers having digit sum 9 there are 9 numbers-18,27,36,45,54,63,72,81 and 90.
Then 16...........-79,88 and 97
Hence there are 17 possibilities.
Log in to reply
Log in to reply
@Agnishom Chattopadhyay – haha! Next time use the scratchpad.
You are looking for what the digits add up to, not the number of digits. You are misleading people with the question.
just write a c code..and its done ;)
1 → 1 0 ⇒ 1
4 → 1 3 , 2 2 , 3 1 , 4 0 ⇒ 4
9 → 1 8 , 2 7 , . . . , 9 0 ⇒ 9
1 6 → 9 7 , 8 8 , 7 9 ⇒ 3
total: 1 7
You can solve this problem by exhaustion (listing all the possibilities). It is useful to note that any 2-digit multiple of 9 (except 99) will have its digit sum as 9 which is a perfect square (i.e. 18, 27, 36, 45, 54, 63, 72, 81, 90). 99 is the exception since its digits sum is 18 which is not a perfect square.
#include<math.h>
using namespace std;
bool isPerfectSquare(long long n){
long long squareRootN=(long long)round((sqrt(n)));
if(squareRootN*squareRootN == n) {
return true;
}
else {
return false;
}}
int sum(int x){
int re=(x%10);
x/=10;
re+=x;
return (re);
}
int main() {
int s=0;
for (int i=10;i<=99;i++){
if (isPerfectSquare(sum(i))==1) s+=1;
}
cout<<s;
return 0;
}
Problem Loading...
Note Loading...
Set Loading...
Let n = 1 0 a + b . We have that 1 < = a < = 9 and 0 < = b < = 9 , so 0 < = a + b < = 1 8 . The perfect squares for that range is 1 , 4 , 9 and 1 6 . For the case 1 , 1 0 is unique because you can't raise b and lower a and a + b remain as 1 . For the case 4 the higher value is 4 0 , so we have 4 possibilities because 1 < = a < = 4 . For the case 9 , 9 0 is the higher value, 1 < = a < = 9 so we have 9 possibilities. Finally, for the case 1 6 , 9 7 is the higher value, as we lower a and raise b we will have only 3 possibilities because b already started at 7 . Summing all possibilities: 1 + 4 + 9 + 3 = 1 7 .