結果

問題 No.982 Add
ユーザー sima.tettekesima.tetteke
提出日時 2020-03-09 13:19:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,011 bytes
コンパイル時間 2,499 ms
コンパイル使用メモリ 163,832 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 10:25:08
合計ジャッジ時間 2,394 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

//互いに素な整数同士はax+by=Nであらゆる整数を作れちゃう
//https://examist.jp/mathematics/integer/axby-kouzou/
//(1)aとbが互いに素(GCDが1)のときab+1以上の全ての自然数(1,2,3...)Nはax+byで表せれる
//(1)のとき表せない最大の自然数はab
//(a-1)(b-1)以上の全ての自然数Nは0以上の整数でax+byで表せれる
ll gcd(ll a, ll b){
    if(b == 0){
        return a;
    }
    return gcd(b, a % b);
}

int main(){

    ll A, B;
    cin >> A >> B;

    //非負整数(0以上の整数)
    //つまり(a-1)(b-1)以上の整数は全て作れる
    //作れない整数はaとbの倍数を除いたもの

    if(gcd(A, B) == 1){
        cout << (A-1)*(B-1)/2 << endl;
    }else{
        cout << -1 << endl;
    }

}
0