文章
99
粉丝
120
获赞
8
访问
97.5k
#include <stdio.h>
int root(int N,int k)
{
if(N >= k)
{
int num = 0;
while(N != 0)
{
num += N%k;
N /= k;
}
return root(num,k);
}
else
return N;
}
void get(int x,int y,int k) // root(x*y,k) = root(root(x,k)*root(y,k),k)
{
int tmp = root(x,k);
int rtn = 1;
while(y>0)
{
if(y%2 == 1)
{
rtn = root(rtn*tmp,k);
}
tmp = root(tmp*tmp,k);
y/=2;
}
printf("%d\n",rtn);
}
int main()
{
int x,y,k;
while(scanf("%d%d%d",&x,&y,&k) != EOF)
{
get(x,y,k);
}
}
登录后发布评论
暂无评论,来抢沙发