結果

問題 No.2324 Two Countries within UEC
ユーザー p3lover
提出日時 2023-05-28 14:06:38
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 705 bytes
コンパイル時間 848 ms
コンパイル使用メモリ 70,756 KB
実行使用メモリ 1,566,168 KB
最終ジャッジ日時 2024-12-26 23:26:45
合計ジャッジ時間 55,293 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 10 RE * 2 TLE * 7 MLE * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

int main() {
    int N, M, P, Q;
    std::cin >> N >> M >> P >> Q;

    std::vector<int> modP(M + 1);  // j%P の結果を保持する配列
    for (int j = 1; j <= M; j++) {
        modP[j] = j % P;
    }

    for (int i = 0; i < Q; i++) {
        int x, f;
        std::cin >> x >> f;
        int ans = 0;

        int modX = x % P;  // x%P の結果を保持

        for (int j = 1; j <= M; j++) {
            if(j<P)if((j * modX) % P == f) {
                ans++;
                continue;
            }
            if ((modP[j] * modX) % P == f) {
                ans++;
            }
        }

        std::cout << ans << std::endl;
    }

    return 0;
}
0