結果
| 問題 |
No.1200 お菓子配り-3
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-28 21:54:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,264 bytes |
| コンパイル時間 | 1,574 ms |
| コンパイル使用メモリ | 167,492 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-14 14:38:39 |
| 合計ジャッジ時間 | 27,951 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 WA * 26 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
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;
// 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) {
++res;
/*
ll a = i - 1;
ll c = (y - j) / (i - 2);
ll b = j - c;
res += (a > 0 && b > 0 && c > 0);*/
}
// b + c == i, a + 1 == j
// c == (y - i) / (j - 2)
if (j > 2 && y > i && (y - i) % (j - 2) == 0) {
++res;
/*
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;
}