hdu 4432 Sum of divisors(十进制转其他进制)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4432
代码:
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int sum; int n,k; int tranfer(int num) { int ret = 0; while(num > 0) { int a = num%k; num = num/k; ret += a*a; } return ret; } int main() { // freopen("E:\\acm\\input.txt","r",stdin); while(cin>>n>>k) { int ans[100],cnt; cnt = 0; sum = 0; for(int i=1; i*i<=n; i++) { if(n % i) continue; if(i*i == n) sum += tranfer(i); else sum += tranfer(i) + tranfer(n/i); } while(sum > 0) { ans[++cnt] = sum%k; sum /= k; } for(int i=cnt; i>=1; i--) { if(ans[i]>9) { printf("%c",ans[i]-10+'A'); } else { printf("%d",ans[i]); } } printf("\n"); } }