标签:des style blog io color ar sp for div
1 #include <stdio.h> 2 3 int change(int number,int m); 4 5 int main(){ 6 int n; 7 int m; 8 int i; 9 int j; 10 int length; 11 int sum; 12 int temp; 13 char s[100]; 14 15 while(scanf("%d%d",&n,&m)!=EOF){ 16 sum=0; 17 for(i=1;i*i<=n;i++){ //这里i*i<=n,如果i从1到n则超时 18 if(n%i==0){ 19 temp=change(i,m); 20 sum+=temp; 21 22 if(i!=n/i){ //如果i和n/i相等则算一次 23 temp=change(n/i,m); 24 sum+=temp; 25 } 26 } 27 } 28 29 i=0; 30 while(sum){ 31 temp=sum%m; 32 33 if(temp<=9) 34 s[i]=temp+‘0‘; 35 36 else if(temp==10) 37 s[i]=‘A‘; 38 39 else if(temp==11) 40 s[i]=‘B‘; 41 42 else if(temp==12) 43 s[i]=‘C‘; 44 45 else if(temp==13) 46 s[i]=‘D‘; 47 48 else if(temp==14) 49 s[i]=‘E‘; 50 51 else if(temp==15) 52 s[i]=‘F‘; 53 54 i++; 55 sum/=m; 56 } 57 58 length=i; 59 60 for(i=length-1;i>=0;i--) 61 printf("%c",s[i]); 62 63 printf("\n"); 64 } 65 66 return 0; 67 } 68 69 int change(int number,int m){ 70 int temp; 71 int result; 72 73 result=0; 74 while(number){ 75 temp=number%m; 76 result+=temp*temp; 77 number/=m; 78 } 79 return result; 80 }
标签:des style blog io color ar sp for div
原文地址:http://www.cnblogs.com/zqxLonely/p/4090205.html