結果
| 問題 |
No.1200 お菓子配り-3
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-28 22:48:53 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,489 bytes |
| コンパイル時間 | 2,497 ms |
| コンパイル使用メモリ | 199,992 KB |
| 最終ジャッジ日時 | 2025-01-13 18:50:19 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 26 WA * 2 TLE * 3 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
ll X, Y;
cin >> X >> Y;
if (X == Y) {
ll ans = X - 1;
ll t = 2;
while (t * t <= X) {
if (X % t == 0) {
if (t * t == X) {
ans++;
} else {
ans += 2;
}
}
t++;
}
if (X > 1) {
ans += 1;
}
cout << ans << "\n";
return;
}
if (X < Y) {
swap(X, Y);
}
ll PN = X + Y;
unordered_map<ll, ll> plus;
ll t = 1;
while (t * t <= PN) {
if (PN % t == 0) {
plus[t] = PN / t;
plus[PN / t] = t;
}
t++;
}
ll MN = X - Y;
unordered_map<ll, ll> minus;
t = 1;
while (t * t <= MN) {
if (MN % t == 0) {
minus[t] = MN / t;
minus[MN / t] = t;
}
t++;
}
ll ans = 0;
for (auto itr = minus.begin(); itr != minus.end(); ++itr) {
ll num = itr->first;
ll target = itr->second;
if (plus.find(num + 2) != plus.end()) {
if ((plus[num + 2] + target) % 2 == 0 && plus[num + 2] > target) {
ans++;
}
}
}
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll S;
cin >> S;
for (int i = 0; i < S; i++) {
solve();
}
return 0;
}