请问为什么只对了#3,#4,#5,而其他TLE?
查看原帖
请问为什么只对了#3,#4,#5,而其他TLE?
317008
青溪白石楼主2021/10/15 13:03

代码如下

#include<iostream>
using namespace std;
inline long long read(){
   long long s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();
   return s*w;
}
bool check(unsigned long long n, int p){
	int cnt = 0;
	while(!(n % p)){
        cnt ++;
        n /= p;
    }
    return !(cnt % 2);
}
int main(){
	int t;
	cin >> t;
	while(t--){
		unsigned long long n = read(), p = read();
		long long ans = n - n / p;
		for(unsigned long long i = p; i <= n; i += p){
			ans += check(i, p);
		}
		printf("%lld\n", ans);
	}
	
}
2021/10/15 13:03
加载中...