How about this?
#include<stdio.h>
void main(){
int pow,n,n2,sq;
scanf("%d",&n);
n2=n,pow=1,sq=0;
while(n2>0){
sq=(sq+(n%(1000000000/pow))*pow*(n2%10))%1000000000;
n2/=10;
pow*=10;
}
printf("%d\n",sq);
}
TIme Complexity O(log n)
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.