結果
| 問題 |
No.1200 お菓子配り-3
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-28 22:48:53 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,195 bytes |
| コンパイル時間 | 2,176 ms |
| コンパイル使用メモリ | 191,452 KB |
| 最終ジャッジ日時 | 2025-01-13 18:50:58 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 29 WA * 2 |
コンパイルメッセージ
main.cpp: In function ‘void solve()’:
main.cpp:23:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
23 | scanf("%lld%lld", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:53:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
53 | scanf("%d", &t);
| ~~~~~^~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using ll = long long;
ll x, y;
void subsolve() {
ll ans = 0;
for(int i = 1; i * i <= x; ++i) {
if(i * i > x)
break;
if(x % i)
continue;
if(x / i > 1)
ans += 1;
if(x != i * i && x / (x / i) > 1)
ans += 1;
}
ans += x;
printf("%lld\n", ans);
}
void solve() {
scanf("%lld%lld", &x, &y);
if(x == y) {
subsolve();
return;
}
if(x < y)
std::swap(x, y);
ll ans = 0;
auto check = [&](ll a) {
if(a >= 2 && (x + y) % (a + 1) == 0 && (x - y) % (a - 1) == 0) {
ll bpc = (x + y) / (a + 1);
ll bmc = (x - y) / (a - 1);
ll b = (bpc + bmc) / 2;
ll c = x - a * b;
if(b > 0 && c > 0 && a * c + b == y)
ans += 1;
}
};
for(ll u = 1; u * u <= x + y; ++u) {
if((x + y) % u)
continue;
check(u - 1);
if((x + y) != u * u)
check((x + y) / u - 1);
}
printf("%lld\n", ans);
}
int main() {
int t;
scanf("%d", &t);
for(int i = 0; i < t; ++i) {
solve();
}
return 0;
}