关于深基上代码的问题
查看原帖
关于深基上代码的问题
759274
Stevehim楼主2023/1/4 21:06

为什么还要再加一个

if(b1 / x != x)

的判定啊。 源代码(有改动)如下

#include <bits/stdc++.h>
using namespace std;

int lcm(int x,int y){
	return x / __gcd(x,y) * y;
}
int t;
int a0,a1,b0,b1;
int ans;
int main() {
	cin >> t;
	while(t--){
		cin >> a0 >> a1 >> b0 >> b1;
		for(int x = 1; x <= b1/ x; x++){
			if(b1 %x == 0){
				if(__gcd(x,a0) == a1 && lcm(x,b0) == b1){
					ans++;
				}
				if(b1 / x != x){
					if(__gcd(b1 / x,a0) == a1 && lcm(b1 / x, b0) == b1){
						ans++;
					}
				}
			}
		}
		cout << ans << endl;
		ans = 0;
	}
	return 0;
}
2023/1/4 21:06
加载中...