http://acm.hdu.edu.cn/showproblem.php?pid=4432
题目很简单 但要注意10进制以上的输出
代码:
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<set> #include<queue> #include<map> #include<string> #include <iomanip> using namespace std; #define LL long long const int INF=0x3f3f3f3f; vector<LL>ans; LL F(LL x,LL k) { LL tmp=0; while(x) { tmp+=(x%k)*(x%k); x=x/k; } return tmp; } int main() { //freopen("data.txt","r",stdin); LL n,k; while(cin>>n>>k) { LL sum=0; LL m=(LL)(sqrt(1.0*n)); for(LL i=1;i<=m;++i) { if(n%i==0) { sum+=F(i,k); if(n/i!=i) sum+=F(n/i,k); } } ans.clear(); while(sum) { ans.insert(ans.begin(),sum%k); sum=sum/k; } for(unsigned int i=0;i<ans.size();++i) { if(ans[i]>=10) { printf("%c",ans[i]-10+'A'); }else cout<<ans[i]; } cout<<endl; } return 0; }