結果

問題 No.1358 [Zelkova 2nd Tune *] 語るなら枚数を...
ユーザー vkgainzvkgainz
提出日時 2021-06-12 12:05:36
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 998 bytes
コンパイル時間 2,609 ms
コンパイル使用メモリ 163,840 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-09 15:16:26
合計ジャッジ時間 3,442 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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