关于我debug没删过了样例4这回事
查看原帖
关于我debug没删过了样例4这回事
443664
Missa楼主2022/3/27 09:10

rt,交了好多遍都不过才发现。

#include <cstdio>
#include <cmath>
#define LL unsigned long long
using namespace std;
LL t, x, z, ans;
int v(LL p, LL &n){
	int ans2 = 0;
	while(n % p == 0) {n /= p; ans2++;}
	return ans2;
}
LL qpow(int a, int b){
	LL ans = 1;
	for(; b; b >>= 1) {if(b & 1) ans *= 1ll * a; a *= 1ll * a;}
	return ans;
}
bool calc(int i){
	if(x % i) return 1;
	int ans1 = v(i, z), ans2 = 0;
	while(x % i == 0) {x /= i; ans2++;}
	ans1 -= ans2;
	if(ans1 <= 2 * ans2){
		if(ans1 % 2 == 1){
			printf("-1\n"); return printf("%d\n", i), 0; //就这里
		} else {
			ans *= qpow(i, ans1 / 2);
		}
	} else {
		ans *= qpow(i, ans1 - ans2);
	}
	return 1;
}
int main(){
	//freopen("math3.in", "r", stdin);
	//freopen("math.out", "w", stdout);
	scanf("%lld", &t);
	while(t--){
		scanf("%llu %llu", &x, &z); ans = 1; bool f = 1;
		if(z % x) {printf("-1\n"); continue;}
		for(LL i = 2; i * i <= x; i++){
			f &= calc(i);
		}
		if(x > 1) f &= calc(x);
		if(z > 1) ans *= z;
		if(f) printf("%llu\n", ans);
	}
}
/*
595420 398241331441380
*/

ccf是怎么造大样例的啊?这还能fc过大样例?

2022/3/27 09:10
加载中...