結果

問題 No.2324 Two Countries within UEC
ユーザー FplusFplusFFplusFplusF
提出日時 2023-05-28 14:05:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 242 ms / 2,000 ms
コード長 1,126 bytes
コンパイル時間 1,971 ms
コンパイル使用メモリ 197,980 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-09 06:10:48
合計ジャッジ時間 8,095 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 232 ms
4,380 KB
testcase_01 AC 242 ms
4,380 KB
testcase_02 AC 43 ms
4,380 KB
testcase_03 AC 180 ms
4,380 KB
testcase_04 AC 206 ms
4,380 KB
testcase_05 AC 46 ms
4,376 KB
testcase_06 AC 84 ms
4,380 KB
testcase_07 AC 38 ms
4,380 KB
testcase_08 AC 183 ms
4,376 KB
testcase_09 AC 186 ms
4,376 KB
testcase_10 AC 239 ms
4,380 KB
testcase_11 AC 240 ms
4,380 KB
testcase_12 AC 73 ms
4,380 KB
testcase_13 AC 74 ms
4,376 KB
testcase_14 AC 44 ms
4,380 KB
testcase_15 AC 37 ms
4,380 KB
testcase_16 AC 161 ms
4,376 KB
testcase_17 AC 104 ms
4,376 KB
testcase_18 AC 47 ms
4,380 KB
testcase_19 AC 238 ms
4,380 KB
testcase_20 AC 31 ms
4,380 KB
testcase_21 AC 179 ms
4,376 KB
testcase_22 AC 231 ms
4,380 KB
testcase_23 AC 73 ms
4,380 KB
testcase_24 AC 192 ms
4,380 KB
testcase_25 AC 239 ms
4,380 KB
testcase_26 AC 25 ms
4,380 KB
testcase_27 AC 28 ms
4,376 KB
testcase_28 AC 26 ms
4,380 KB
testcase_29 AC 25 ms
4,380 KB
testcase_30 AC 26 ms
4,376 KB
testcase_31 AC 2 ms
4,504 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll,ll>;
const ll INF=(1ll<<60);
#define rep(i,n) for (ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(),v.end()
template<class T> void chmin(T &a,T b){
    if(a>b){
        a=b;
    }
}
template<class T> void chmax(T &a,T b){
    if(a<b){
        a=b;
    }
}
ll modpow(ll a,ll b,ll mod){
    if(mod==1) return 0;
    if(b==0) return 1;
    ll p=a,ret=1;
    for(ll i=0;i<=62;i++){
        if(b&(1ll<<i)){
            ret*=p;
            ret%=mod;
        }
        p=(p%mod)*(p%mod);
        p%=mod;
    }
    return ret;
}
ll division(ll a,ll b,ll mod){
    return (a*modpow(b,mod-2,mod))%mod;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,m,p,q;
    cin >> n >> m >> p >> q;
    while(q--){
        ll x,f;
        cin >> x >> f;
        if(x%p==0){
            if(f==0) cout << m << '\n';
            else cout << "0\n";
            continue;
        }
        ll s=division(f,x,p);
        if(s==0) s+=p;
        if(s<=m) cout << 1+(m-s)/p << '\n';
        else cout << "0\n";
    }
}
0