結果

問題 No.2324 Two Countries within UEC
ユーザー CleyLCleyL
提出日時 2023-10-18 18:27:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 239 ms / 2,000 ms
コード長 2,058 bytes
コンパイル時間 903 ms
コンパイル使用メモリ 69,652 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 18:27:18
合計ジャッジ時間 10,214 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 225 ms
4,348 KB
testcase_01 AC 236 ms
4,348 KB
testcase_02 AC 45 ms
4,348 KB
testcase_03 AC 176 ms
4,348 KB
testcase_04 AC 204 ms
4,348 KB
testcase_05 AC 45 ms
4,348 KB
testcase_06 AC 82 ms
4,348 KB
testcase_07 AC 37 ms
4,348 KB
testcase_08 AC 175 ms
4,348 KB
testcase_09 AC 181 ms
4,348 KB
testcase_10 AC 239 ms
4,348 KB
testcase_11 AC 231 ms
4,348 KB
testcase_12 AC 71 ms
4,348 KB
testcase_13 AC 70 ms
4,348 KB
testcase_14 AC 42 ms
4,348 KB
testcase_15 AC 38 ms
4,348 KB
testcase_16 AC 159 ms
4,348 KB
testcase_17 AC 101 ms
4,348 KB
testcase_18 AC 47 ms
4,348 KB
testcase_19 AC 236 ms
4,348 KB
testcase_20 AC 32 ms
4,348 KB
testcase_21 AC 159 ms
4,348 KB
testcase_22 AC 203 ms
4,348 KB
testcase_23 AC 64 ms
4,348 KB
testcase_24 AC 167 ms
4,348 KB
testcase_25 AC 236 ms
4,348 KB
testcase_26 AC 191 ms
4,348 KB
testcase_27 AC 205 ms
4,348 KB
testcase_28 AC 195 ms
4,348 KB
testcase_29 AC 189 ms
4,348 KB
testcase_30 AC 192 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 2 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 2 ms
4,348 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 1 ms
4,348 KB
testcase_42 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;



struct ModInt{
  int n;
  int mod;
  ModInt(int mod, int n_):mod(mod), n(n_ >= 0 ? n_%mod : mod - ((-n_)%mod) ){}

  ModInt &operator+=(const ModInt &p){
    if((n+=p.n) >= mod)n-=mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p){
    n+=mod-p.n;
    if(n >= mod)n-=mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p){
    n = (int) ((1LL*n*p.n)%mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p){
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const {return ModInt(mod, -n);}
  ModInt operator+(const ModInt &p) const {return ModInt(*this) += p;}
  ModInt operator-(const ModInt &p) const {return ModInt(*this) -= p;}
  ModInt operator*(const ModInt &p) const {return ModInt(*this) *= p;}
  ModInt operator/(const ModInt &p) const {return ModInt(*this) /= p;}

  bool operator==(const ModInt &p) const {return n==p.n;}
	bool operator<(const ModInt &p) const {return n<p.n;}
	bool operator>(const ModInt &p) const {return n>p.n;}
	bool operator>=(const ModInt &p) const {return n>=p.n;}
	bool operator<=(const ModInt &p) const {return n<=p.n;}
  bool operator!=(const ModInt &p) const {return n!=p.n;}

  ModInt inverse() const {
    int a = n,b = mod,u = 1,v = 0;
    while(b){
      int t = a/b;
      a -= t*b; swap(a,b);
      u -= t*v; swap(u,v);
    }
    ModInt ret(mod, u);
    return ret;
  }

  ModInt pow(int64_t z) const {
    ModInt ret(mod, 1),mul(mod, n);
    while(z > 0){
      if(z & 1) ret *= mul;
      mul *= mul;
      z >>= 1;
    }
    return ret;
  }

  int toInt(){
    return n;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p){
    return os << p.n;
  }
};

int main(){
  long long n,m,p,q;cin>>n>>m>>p>>q;
  for(int i = 0; q > i; i++){
    long long X,F;cin>>X>>F;
    ModInt x(p,X),f(p,F);
    if(x.toInt() == 0){
      if(f.toInt() == 0)cout << m << endl;
      else cout << 0 << endl;
    }else{
      (f/x).toInt();
      cout << m/p + ((f/x).toInt() <= (m%p) && f.toInt() != 0) << endl;
    }

  }
}
0