結果

問題 No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
ユーザー vkgainzvkgainz
提出日時 2021-06-12 12:05:36
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 998 bytes
コンパイル時間 2,143 ms
コンパイル使用メモリ 133,600 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-08-22 09:41:00
合計ジャッジ時間 6,819 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
7,620 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,504 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 45 ms
4,376 KB
testcase_07 AC 55 ms
4,376 KB
testcase_08 AC 109 ms
4,380 KB
testcase_09 AC 263 ms
4,380 KB
testcase_10 AC 115 ms
4,376 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:37:12: warning: variable 'N' is uninitialized when used here [-Wuninitialized]
        if(N > K) swap(N, K);
           ^
main.cpp:36:14: note: initialize the variable 'N' to silence this warning
        int N, K, H;
             ^
              = 0
main.cpp:38:16: warning: variable 'H' is uninitialized when used here [-Wuninitialized]
        if(N > H) swap(N, H);
               ^
main.cpp:36:20: note: initialize the variable 'H' to silence this warning
        int N, K, H;
                   ^
                    = 0
main.cpp:37:16: warning: variable 'K' is uninitialized when used here [-Wuninitialized]
        if(N > K) swap(N, K);
               ^
main.cpp:36:17: note: initialize the variable 'K' to silence this warning
        int N, K, H;
                ^
                 = 0
3 warnings generated.

ソースコード

diff #

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

int inv(int a, int m) {
    int m0 = m;
    long long y = 0, x = 1;
    if(m == 1) return 0;
    while(a > 1) {
        int q = a / m, t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * 1LL * y;
        x = t;
    }
    if(x < 0) x += m0;
    return x;
}

int num(long long Y, int K, int H) {
    int mx = Y / K;
    long long g = __gcd(K, H);
    g = __gcd(g, Y);
    K /= g, Y /= g, H /= g;
    if(__gcd(K, H) > 1) return 0;
    long long st = Y % H * inv(K, H);
    st %= H;
    if(st > mx) return 0;
    return (mx - st) / H + 1;
}

long long MOD = 1e9 + 7;

int main() {
    int T; cin >> T;
    while(T--) {
        int N, K, H;
        if(N > K) swap(N, K);
        if(N > H) swap(N, H);
        long long Y;
        cin >> N >> K >> H >> Y;
        long long ans = 0LL;
        for(int i = 0; i <= Y / N; i++) {
            ans += num(Y - N * 1LL * i, K, H);
        }
        ans %= MOD;
        cout << ans << "\n";
    }
}
0