#include<iostream>
#include<cstdio>
int solve(int n,int k)
{
int sign=1,ans=0;
while(n)
{
ans+=sign*n;
n/=k;
sign=-sign;
}
return ans;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,k;
scanf("%d%d",&n,&k);
printf("%d\n",solve(n,k));
}
return 0;
}
UVA 11246(p350)----K-Multipe Free Set
最新推荐文章于 2022-01-02 00:25:46 发布