結果

問題 No.1158 GCD Products easy
ユーザー Hydrogen332
提出日時 2024-10-27 20:53:35
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 707 bytes
コンパイル時間 2,182 ms
コンパイル使用メモリ 195,756 KB
最終ジャッジ日時 2025-02-25 00:56:03
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (int i = (int)s; i < (int)e; ++i)
#define all(a) (a).begin(), (a).end()

const ll mod = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    
    ll A, B, N;
    cin >> A >> B >> N;
    
    ll ans = 1;
    vector<int> vec(N, A);
    while (true) {
        if (vec[N - 1] == B + 1) break;
        
        ll g = vec[0];
        rep(i, 1, N) g = gcd(g, vec[i]);
        
        ans *= g;
        ans %= mod;
        
        vec[0]++;
        rep(i, 0, N - 1) {
            if (vec[i] == B + 1) {
                vec[i] = A;
                vec[i + 1]++;
            }
        } 
    }
    
    cout << ans << '\n';
}
0