結果

問題 No.3020 ユークリッドの互除法・改
ユーザー GOTKAKO
提出日時 2025-02-14 21:37:33
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 973 bytes
コンパイル時間 2,322 ms
コンパイル使用メモリ 199,700 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2025-02-14 21:37:36
合計ジャッジ時間 2,896 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 3 WA * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    vector<vector<long long>> A(2,vector<long long>(2));
    cin >> A[0][0] >> A[0][1] >> A[1][0] >> A[1][1];

    while(A.at(0).at(1) > 0 && A.at(1).at(0) > 0){
        while(A.at(0).at(1) > 0){
            if(A.at(1).at(1) == 0){
                swap(A.at(0),A.at(1));
                continue;
            }
            long long x = A.at(0).at(1),y = A.at(1).at(1);
            if(x < 0) for(auto &a : A.at(0)) a *= -1;
            if(y < 0) for(auto &a : A.at(1)) a *= -1;
            x = abs(x); y = abs(y);
            if(x < y) swap(x,y),swap(A.at(0),A.at(1));

            long long d = x/y;
            for(int i=0; i<2; i++) A.at(0).at(i) -= A.at(1).at(i)*d;

        }
        swap(A.at(1).at(0),A.at(0).at(1));
    }
    long long x = A.at(0).at(0),y = A.at(1).at(1);
    x = abs(x); y = abs(y);
    
    cout << 1 << " " << x*y << endl;
}
0