#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
#include<vector>
#include<cmath>
#define mm(a,b) memset(a,b,sizeof(a))
#define ACCELERATE (ios::sync_with_stdio(false),cin.tie(0))
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
int main()
{
int n,m,q;
scanf("%d",&n);
while(n--)
{
scanf("%d%d",&m,&q);
double s=log10(2.0*m)/log10(q*1.0);
int t=1;
int cnt=0;
for(int i=0;i<(int)s;i++)
{
t*=q;
cnt+=2*m/t-2*(m/t);
}
printf("%d\n",cnt);
}
return 0;
}
nefu 119 (组合素数)
最新推荐文章于 2022-01-11 15:58:37 发布