結果
問題 | No.1200 お菓子配り-3 |
ユーザー |
|
提出日時 | 2020-08-28 21:57:35 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,186 bytes |
コンパイル時間 | 1,775 ms |
コンパイル使用メモリ | 167,636 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-14 14:44:51 |
合計ジャッジ時間 | 10,844 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 29 WA * 2 |
ソースコード
#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; // 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); } // 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; }