We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- All Contests
- ProjectEuler+
- Project Euler #171: Finding numbers for which the sum of the squares of the digits is a square
- Discussions
Project Euler #171: Finding numbers for which the sum of the squares of the digits is a square
Project Euler #171: Finding numbers for which the sum of the squares of the digits is a square
Sort by
recency
|
71 Discussions
|
Please Login in order to post a comment
Not so easy task. It can be solved using clever dynamic programming, focusing on digit by digit processing. Search space should be defined by the maximum value of square digit sum. For given square digit sum we also need to keep track of its frequency. Maximum time is around 50 ms for values of k in the order of 10^100.
I have passed 5 test cases can anyone please help how to optimise code for larger input
for all those guess who does not understant the question trick question sample case 100 how you get 826 then the logic behind that you searched the no from 0 to 100 then then you have to do that for example 86 when we break this no it get 8 and 6 whose square sum is 100 who is the precfect square so that why this the number 43 4^2=16 and 3^2=9 then its is a perfect square no hope youunderstand the logic
include
include
include
include
int main() { unsigned long i,j,n,squares_of_sum=0,sum=0,rem,square=0,temp; scanf("%d",&n); for(i=1;i<=n;i++) { temp=i; while(temp) { rem=temp%10; sum=(sum+(rem*rem)); temp/=10; } sum=sum%1000000007; rem=temp=0; square=sqrt(sum); if(sum==(pow(square,2))) squares_of_sum+=i; sum=square=0; }
}
what's the error in it can anyone tell that...