結果

問題 No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
コンテスト
ユーザー roaris
提出日時 2021-01-23 19:18:42
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,385 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,378 ms
コンパイル使用メモリ 211,608 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-17 09:31:24
合計ジャッジ時間 5,349 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 1 WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;

int extGCD(int a, int b, int &x, int &y) {
    if (b==0) {
        x = 1;
        y = 0;
        return a;
    }
    int d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}

signed main() {
    int T; cin >> T;
    int x, y;
    
    while (T--) {
        int N, K, H, Y; cin >> N >> K >> H >> Y;
        int M = max({N, K, H});
        int c = Y/M;
        int ans = 0;
        
        for (int i=0; i<=c; i++) {
            int nokori = Y-i*M;
            
            if (M==N) {
                int G = extGCD(K, H, x, y);
                if (nokori%G==0) {
                    x *= nokori/G;
                    y *= nokori/G;
                    ans += y/K-(-x+H-1)/H+1;
                }
            }
            else if (M==K) {
                int G = extGCD(H, N, x, y);
                if (nokori%G==0) {
                    x *= nokori/G;
                    y *= nokori/G;
                    ans += y/H-(-x+N-1)/N+1;
                }
            }
            else {
                int G = extGCD(N, K, x, y);
                if (nokori%G==0) {
                    x *= nokori/G;
                    y *= nokori/G;
                    ans += y/N-(-x+K-1)/K+1;
                }
            }
            ans %= MOD;
        }
        cout << ans << endl;
    }
}
0