2huk
2024-11-15 15:43:17
先考虑如何判断
不难发现一个必要条件是
满足这个条件的
然后猜出充分条件是
考察第二个条件。可以改写成:
于是可以对
于是需要预处理
// Problem:
// P9031 [COCI2022-2023#1] Iksevi
//
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P9031
// Memory Limit: 512 MB
// Time Limit: 3000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#define tests
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int D[N];
void solve() {
int x, y;
cin >> x >> y;
if ((x + y) % 2) cout << D[__gcd(x, y)] << '\n';
else cout << D[__gcd(x, y)] - D[__gcd(__gcd(x, y), x + y >> 1)] << '\n';
}
signed main() {
for (int i = 1; i < N; ++ i )
for (int j = i; j < N; j += i) D[j] ++ ;
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T = 1;
#ifdef tests
cin >> T;
#endif
while (T -- ) solve();
return 0;
}