玄学RE求调
查看原帖
玄学RE求调
359113
elbissoPtImaerD楼主2021/10/4 08:14

哪位好心人帮我调调吧 /kel

评测记录

Code:Code:

#include<cstdio>
#include<cmath>
#define ll long long
#define re register
using namespace std;
inline ll read()
{
	re ll now=0,f=1;
	char xr=getchar();
	while('0'>xr||xr>'9')
	{
		if(xr=='-') f=-1;
		xr=getchar();
	}
	while('0'<=xr&&xr<='9')
		now=(now<<1)+(now<<3)+(xr^48),xr=getchar();
	return now*f;
}
//void write(ll sq)
//{
//	if(sq>9)
//		write(sq/10);
//	putchar(sq%10+48);
//	return;
//}
int t;
ll n,p;
ll tmp,cnt,ans;
int main()
{
	t=read();
//	scanf("%d",&t);
	while(t--)
	{
		n=read(),p=read();	
//		scanf("%lld%lld",&n,&p);
		tmp=1,cnt=0,ans=n;
		if(p==1)
		{
//			write(0),putchar('\n');
			printf("0\n");
			continue;
		}
		while(true)
		{
			tmp*=p,++cnt;
			if(tmp>n||tmp<=0)
				break;
			if(cnt&1)
				ans-=(n/tmp);
			else
				ans+=(n/tmp);
		}
//		write(ans),putchar('\n');
		printf("%lld\n",ans);
	}
	return 0;
}
2021/10/4 08:14
加载中...