无思路求教
查看原帖
无思路求教
1295409
akahoshi楼主2024/6/3 13:37
#include <bits/stdc++.h>

typedef long long ll;
ll a0, a1, b0, b1;

void solve(){
	ll s = 0;
	std::cin >> a0 >> a1 >> b0 >> b1;
	if (b1%a1){
		std::cout << s << std::endl;
		return;
	}
	ll n = b1 / a1; // x | b1 && a1 | x
	// n | x && x | b1
	// => x = a * n
	// while 1 <= a <= b1/n
	for (ll a = 1; a<= b1/n; a++){
		ll x = a * n;
		if (std::__gcd(b1/b0, b1/x) == 1 && std::__gcd(x/a1, a0/a1) == 1) ++s;
	}
	std::cout << s << std::endl;
}

int main(){
	int t;
	std::cin >> t;
	while(t--){
		solve();
	}
}

个人感觉思路没啥问题

2024/6/3 13:37
加载中...