結果

問題 No.2324 Two Countries within UEC
ユーザー MMMM
提出日時 2023-05-28 14:12:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 270 ms / 2,000 ms
コード長 958 bytes
コンパイル時間 1,633 ms
コンパイル使用メモリ 167,112 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-09 06:11:43
合計ジャッジ時間 8,926 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 257 ms
4,376 KB
testcase_01 AC 269 ms
4,380 KB
testcase_02 AC 49 ms
4,380 KB
testcase_03 AC 198 ms
4,380 KB
testcase_04 AC 227 ms
4,380 KB
testcase_05 AC 52 ms
4,384 KB
testcase_06 AC 91 ms
4,380 KB
testcase_07 AC 41 ms
4,380 KB
testcase_08 AC 193 ms
4,380 KB
testcase_09 AC 197 ms
4,380 KB
testcase_10 AC 264 ms
4,376 KB
testcase_11 AC 262 ms
4,376 KB
testcase_12 AC 80 ms
4,380 KB
testcase_13 AC 79 ms
4,376 KB
testcase_14 AC 48 ms
4,380 KB
testcase_15 AC 42 ms
4,380 KB
testcase_16 AC 180 ms
4,380 KB
testcase_17 AC 116 ms
4,380 KB
testcase_18 AC 52 ms
4,380 KB
testcase_19 AC 268 ms
4,380 KB
testcase_20 AC 35 ms
4,380 KB
testcase_21 AC 167 ms
4,380 KB
testcase_22 AC 214 ms
4,384 KB
testcase_23 AC 67 ms
4,380 KB
testcase_24 AC 174 ms
4,380 KB
testcase_25 AC 270 ms
4,376 KB
testcase_26 AC 197 ms
4,380 KB
testcase_27 AC 198 ms
4,376 KB
testcase_28 AC 188 ms
4,376 KB
testcase_29 AC 181 ms
4,380 KB
testcase_30 AC 192 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 1 ms
4,384 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,384 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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;
    if(x % P == 0)
      cout << (f == 0 ? M : 0) << endl;
         
    else {
      ll y = (modinv(x,P) * f) % P;
      cout << M / P + (M % P >= y && f > 0) << endl;
    }
  }
}
0