結果
| 問題 |
No.816 Beautiful tuples
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-18 01:41:40 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 659 bytes |
| コンパイル時間 | 1,001 ms |
| コンパイル使用メモリ | 80,016 KB |
| 最終ジャッジ日時 | 2025-01-09 21:03:07 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 11 WA * 4 |
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
using lint = long long;
void solve() {
lint a, b;
std::cin >> a >> b;
auto s = a + b;
std::vector<lint> cs;
for (lint p = 1; p * p <= s; ++p) {
if (s % p != 0) continue;
cs.push_back(p);
cs.push_back(s / p);
}
std::sort(cs.begin(), cs.end());
for (auto c : cs) {
if ((a + c) % b == 0 && (b + c) % a == 0) {
std::cout << c << std::endl;
return;
}
}
std::cout << -1 << std::endl;
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
solve();
return 0;
}