#include<bits/stdc++.h>
using namespace std;
int main()
{
int i,n,m,ans,p,t;
int a[100];
while(~scanf("%d%d",&n,&m))
{
ans=0;
for(i=1; i*i<n; i++)
{
if(n%i==0)
{
p=i;
while(p)
{
t=p%m;
ans+=t*t;
p/=m;
}
p=n/i;
while(p)
{
t=p%m;
ans+=t*t;
p/=m;
}
}
}
if(i*i==n)
{
p=n;
while(p)
{
t=p%m;
ans+=t*t;
p/=m;
}
}
p=0;
while(ans)
{
a[p]=ans%m;
p++;
ans/=m;
}
for(i=p-1; i>=0; i--)
{
if(a[i]<10) printf("%d",a[i]);
else printf("%c",a[i]-10+'A');
}
printf("\n");
}
return 0;
}
hdu 4432 Sum of divisors
最新推荐文章于 2021-04-21 21:28:27 发布