結果

問題 No.2324 Two Countries within UEC
ユーザー MM
提出日時 2023-05-28 13:41:18
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 898 bytes
コンパイル時間 1,892 ms
コンパイル使用メモリ 167,500 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-26 21:30:27
合計ジャッジ時間 9,351 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define chmin(x,y) (x) = min((x),(y))
#define chmax(x,y) (x) = max((x),(y))
using namespace std;
using ll = long long;
const ll mod = 998244353;
const vector<int> dx = {1,0,-1,0}, dy = {0,1,0,-1};
using Graph = vector<vector<int>>;

// https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main(){
  // input
  ll N,M,P,Q; cin >> N >> M >> P >> Q;
  // solve
  while(Q--){
    ll x,f; cin >> x >> f;
    ll y = (modinv(x,P) * f) % P;
    if(f == 0) y += P;
    cout << M / P + (M % P >= y) << endl;

  }
  // output
  
}
0