You are viewing a single comment's thread. Return to all comments →
I have written the following code:
int main() { float check; int i, r, ex, k, s, result=0; scanf("%d",&k); for(i=1; i<=k ; i++) { ex=i; s=0; while(i>0) { r=i%10; s=s+(r*r); i=i/10; } check=(int)(sqrt(s)); if((sqrt(s)-check)==0) result=result+ex; } printf("%d",result);
return 0;
}
Each time I rum the code, it says time-out but I cannot make this any smaller. Some one please give some suggestion.
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 →
I have written the following code:
include
include
int main() { float check; int i, r, ex, k, s, result=0; scanf("%d",&k); for(i=1; i<=k ; i++) { ex=i; s=0; while(i>0) { r=i%10; s=s+(r*r); i=i/10; } check=(int)(sqrt(s)); if((sqrt(s)-check)==0) result=result+ex;
} printf("%d",result);
}
Each time I rum the code, it says time-out but I cannot make this any smaller. Some one please give some suggestion.