代码:
#include#include #include #include 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"); }}