結果

問題 No.2324 Two Countries within UEC
ユーザー kpinkcatkpinkcat
提出日時 2023-09-27 00:00:04
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 286 ms / 2,000 ms
コード長 883 bytes
コンパイル時間 2,422 ms
コンパイル使用メモリ 201,472 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-19 17:41:58
合計ジャッジ時間 9,679 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include<iostream>
#include<map>
#include<vector>
#include <algorithm>
#include<math.h>
#include <iomanip>
#include<set>
#include <numeric>
#include<string>
using ll = long long;
using namespace std;

int main()
{
    ll n, m, p, q;
    cin >> n >> m >> p >> q;
    for (int i = 0; i < q; i++){
        ll x, f, x1 = 1, p1, y;
        cin >> x >> f; 
        if (!(x%p) && f == 0){
            cout << m << endl;
            continue;
        } else if (!(x%p)){
            cout << 0 << endl;
            continue;
        }
        p1 = p - 2;
        while (p1){
            if (p1 & 1){
                x1 *= x;
                x1 %= p;
            }
            x *= x;
            x %= p;
            p1 >>= 1;
        }
        x1 %= p;
        y = x1 * f % p;
        if (!y) cout << m/p << "\n";
        else cout << (m - y + p)/p << "\n";
    }
}

0