結果

問題 No.816 Beautiful tuples
ユーザー vwxyzvwxyz
提出日時 2021-08-09 00:51:30
言語 C++23(draft)
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 596 bytes
コンパイル時間 4,800 ms
コンパイル使用メモリ 282,988 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 01:18:49
合計ジャッジ時間 4,600 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

int main(){
    int A,B;
    cin>>A>>B;
    int ans=-1;
    vector<int> divisors(0);
    vector<int> divisors_rev(0);
    for(int C=1;C*C<=A+B;C++){
        if((A+B)%C==0){
            divisors.push_back(C);
            divisors_rev.push_back((A+B)/C);
        }
    }
    reverse(divisors_rev.begin(),divisors_rev.end());
    for(int d:divisors_rev){
        divisors.push_back(d);
    }
    for(int d:divisors){
        if((A+d)%B==0&&(B+d)%A==0){
            ans=d;
            break;
        }
    }
    cout<<ans<<endl;
}
0