結果

問題 No.982 Add
ユーザー erbowl
提出日時 2020-04-25 14:29:36
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 356 ms / 2,000 ms
コード長 655 bytes
コンパイル時間 2,472 ms
コンパイル使用メモリ 191,824 KB
最終ジャッジ日時 2025-01-10 01:05:34
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    ll a,b;
    std::cin >> a>>b;
    if(gcd(a,b)!=1){
        std::cout << -1 << std::endl;
        return 0;
    }
    ll cnt = 0;
    for (int i = 1; i <= 10000; i++) {
        bool ok = false;
        for (int j = 1; j <= i; j++) {
            // if(i-a*j<0)continue;
            
            if((i-a*j)%b==0&&(i-a*j)>=0){
                ok = true;
                break;
            }
            if((i-b*j)%a==0&&(i-b*j)>=0){
                ok = true;
                break;
            }
        }
        if(!ok)cnt++;
    }
    std::cout << cnt << std::endl;
}

0