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
|
70 Discussions
|
Please Login in order to post a comment
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...
here is my full code.. only four test cases are passed and for rest it shows timedout please help me where the problem is
import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*;
public class Solution {
}