結果
| 問題 |
No.816 Beautiful tuples
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-04-20 02:11:19 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 1,500 ms |
| コード長 | 883 bytes |
| コンパイル時間 | 1,668 ms |
| コンパイル使用メモリ | 171,100 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-24 18:01:16 |
| 合計ジャッジ時間 | 2,305 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
vector<long long> enum_divisor(long long n){
vector<long long> ret;
for (long long i = 1; i * i <= n; ++i){
if (n % i == 0){
ret.push_back(i);
if (i * i != n){
ret.push_back(n / i);
}
}
}
return ret;
}
int main()
{
ios::sync_with_stdio(false);
cout.tie(0);
long long A, B;
cin >> A >> B;
// a + b = k1 * c
// b + c = k2 * a -> (k1*c-a)+c=k2*a ->(k1+1)*c = (k2+1)*a
// c + a = k3 * b -> (c + k1*c-b) = k3*b => (k1+1)*c = (k3+1)*b
// (k2+1)*a = (k3+1)*b
auto cs = enum_divisor(A + B);
long long ans = A + B + 1;
for (auto c: cs){
if ((B + c) % A == 0 and (c + A) % B == 0 and c < ans and c != A and c != B) ans = c;
}
if (ans == A + B + 1) ans = -1;
cout << ans << endl;
return 0;
}