結果
| 問題 |
No.1200 お菓子配り-3
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-30 03:14:12 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,401 bytes |
| コンパイル時間 | 1,560 ms |
| コンパイル使用メモリ | 166,228 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-14 17:51:49 |
| 合計ジャッジ時間 | 11,702 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 2 |
| other | AC * 6 WA * 25 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = int;
constexpr char newl = '\n';
ll solve(ll x, ll y) {
// x = ab+c, y = ac+b
// x + y = (a + 1)(b + c)
ll sum = x + y;
ll res = 0;
for (ll i = 2; i * i <= sum; i++) {
if (sum % i != 0) continue;
ll j = sum / i;
if (i == 2) {
res += j - 1 + (i != j);
continue;
}
if (j == 2) {
res += i - 1 + (i != j);
continue;
}
// a + 1 == i, b + c == j
// (i - 1) c + (j - c) == y
// (i - 2) c + j == y
// c == (y - j) / (i - 2)
if (i > 2 && y > j && (y - j) % (i - 2) == 0) {
ll a = i - 1;
ll c = (y - j) / (i - 2);
ll b = j - c;
res += (a > 0 && b > 0 && c > 0);
}
if (i == j) continue;
// b + c == i, a + 1 == j
// c == (y - i) / (j - 2)
if (j > 2 && y > i && (y - i) % (j - 2) == 0) {
ll a = j - 1;
ll c = (y - i) / (j - 2);
ll b = i - c;
res += (a > 0 && b > 0 && c > 0);
}
}
return res;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
ll x, y;
cin >> x >> y;
cout << solve(x, y) << newl;
}
return 0;
}