結果
| 問題 |
No.816 Beautiful tuples
|
| コンテスト | |
| ユーザー |
tokizo
|
| 提出日時 | 2019-04-20 16:48:34 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,500 ms |
| コード長 | 734 bytes |
| コンパイル時間 | 1,626 ms |
| コンパイル使用メモリ | 171,808 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-01 13:31:20 |
| 合計ジャッジ時間 | 2,257 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int a, b;
cin >> a >> b;
int x = a + b;
vector<int> A;
for(int i = 1; i <= (int)(sqrt(x)); i++){
if(x % i == 0){
A.push_back(i);
A.push_back(x / i);
}
}
sort(A.begin(), A.end());
for(int i = 0; i < A.size(); i++){
if(A[i] != a and A[i] != b){
bool l = (a + b) % A[i] == 0;
bool m = (b + A[i]) % a == 0;
bool n = (A[i] + a) % b == 0;
if(l and m and n){
cout << A[i] << endl;
return 0;
}
}
}
cout << -1 << endl;
return 0;
}
tokizo