結果

問題 No.2324 Two Countries within UEC
ユーザー bluebery1001bluebery1001
提出日時 2023-05-28 16:33:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 278 ms / 2,000 ms
コード長 1,651 bytes
コンパイル時間 3,472 ms
コンパイル使用メモリ 166,872 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-09 06:17:49
合計ジャッジ時間 8,871 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 264 ms
4,380 KB
testcase_01 AC 278 ms
4,384 KB
testcase_02 AC 50 ms
4,380 KB
testcase_03 AC 205 ms
4,384 KB
testcase_04 AC 231 ms
4,380 KB
testcase_05 AC 54 ms
4,380 KB
testcase_06 AC 95 ms
4,380 KB
testcase_07 AC 43 ms
4,380 KB
testcase_08 AC 199 ms
4,380 KB
testcase_09 AC 205 ms
4,376 KB
testcase_10 AC 278 ms
4,376 KB
testcase_11 AC 266 ms
4,376 KB
testcase_12 AC 83 ms
4,384 KB
testcase_13 AC 81 ms
4,380 KB
testcase_14 AC 50 ms
4,376 KB
testcase_15 AC 43 ms
4,384 KB
testcase_16 AC 187 ms
4,380 KB
testcase_17 AC 121 ms
4,376 KB
testcase_18 AC 53 ms
4,380 KB
testcase_19 AC 275 ms
4,376 KB
testcase_20 AC 36 ms
4,380 KB
testcase_21 AC 152 ms
4,376 KB
testcase_22 AC 194 ms
4,380 KB
testcase_23 AC 61 ms
4,376 KB
testcase_24 AC 158 ms
4,380 KB
testcase_25 AC 274 ms
4,380 KB
testcase_26 AC 155 ms
4,380 KB
testcase_27 AC 154 ms
4,376 KB
testcase_28 AC 153 ms
4,376 KB
testcase_29 AC 153 ms
4,376 KB
testcase_30 AC 156 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,384 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,376 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 1 ms
4,384 KB
testcase_42 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using namespace std;
#include<bits/stdc++.h>
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); cout<<fixed<<setprecision(15);_main(); return 0;}
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef long double ld;
template<class ll> inline bool chmax(ll& a, ll b) { if (a < b) { a = b; return 1; } return 0; }
template<class ll> inline bool chmin(ll& a, ll b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i, star,fini) for (int i = star; i < fini; i++)
#define ALL(x) std::begin(x), std::end(x)
#define INF ((1LL<<62)-(1LL<<31))
#define bit(x,i)(((x)>>(i))&1)
long double distance(long double xi,long double yi,long double xj,long double yj){return sqrt(1.0*((xi-xj)*(xi-xj))+1.0*((yi-yj)*(yi-yj)));}
ll n,m,p,q;
long long modpow(long long a, long long n) {
    ll mod = p;
    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) {
    return modpow(a, p - 2);
}

void _main(){
    cin >> n >> m >> p >> q;
    while (q--)
    {
        ll x,f;cin >> x >> f;
        if(f==0){
            if(x%p==0){
                cout<<m<<endl;
                continue;
            }
            else{
                cout<<m/p<<endl;
                continue;
            }
        }
        if(x%p==0){
            cout<<0<<endl;
            continue;
        }
        ll xwf = x*modinv(f)%p;
        ll g_xwf = modinv(xwf);
        g_xwf%=p;
        cout<<max(0ll,m-g_xwf+p)/p-(g_xwf==0)<<endl;
    }
    
}
0