You are viewing a single comment's thread. Return to all comments →
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; }
printf("%lu",abs(squares_of_sum));
}
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #171: Finding numbers for which the sum of the squares of the digits is a square
You are viewing a single comment's thread. Return to all comments →
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; }
}