結果
| 問題 |
No.816 Beautiful tuples
|
| コンテスト | |
| ユーザー |
springroll
|
| 提出日時 | 2019-04-19 21:47:58 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,500 ms |
| コード長 | 1,081 bytes |
| コンパイル時間 | 1,694 ms |
| コンパイル使用メモリ | 170,940 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-22 18:22:57 |
| 合計ジャッジ時間 | 2,135 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define MAX_N (200005)
#define INF (1LL<<60)
#define debug(x) cerr << #x <<":"<< x << endl;
#define debugVec(x) for(auto p:(x)) cerr << p <<" "; cerr << endl;
#define debugVecPair(x) for(auto p:(x)) cerr << #x <<": "<< p.first <<" "<< p.second << endl;
#define debugIdx(i, x) cerr << #i <<" : "<< i <<" "<< #x <<" : "<< x << endl;
const int MOD = (int)1e9+7;
// 約数の列挙O(√n)
vector<int> divisor(int n){
vector<int> res;
for(int i=1; i*i<=n; i++){
if(n%i==0){
res.push_back(i);
// n の約数が i の時、n/i も n の約数になる
if(i!=n/i) res.push_back(n/i);
}
}
return res;
}
signed main() {
int A, B;
cin >> A >> B;
vector<int> C;
C = divisor(A+B);
int ans=INF;
for(int i=0; i<C.size(); i++){
//debug(C[i]);
if(A==C[i] || B==C[i] || A==B) continue;
if((A+C[i])%B==0 && (B+C[i])%A==0){
ans = min(ans, C[i]);
}
}
cout << (ans==INF?-1:ans) << endl;
}
springroll