結果

問題 No.2324 Two Countries within UEC
ユーザー coindarwcoindarw
提出日時 2023-05-28 14:25:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,117 bytes
コンパイル時間 4,241 ms
コンパイル使用メモリ 258,800 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-27 09:44:36
合計ジャッジ時間 13,611 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 442 ms
4,376 KB
testcase_01 AC 325 ms
4,376 KB
testcase_02 AC 18 ms
4,376 KB
testcase_03 AC 163 ms
4,380 KB
testcase_04 AC 390 ms
4,376 KB
testcase_05 AC 75 ms
4,380 KB
testcase_06 AC 158 ms
4,376 KB
testcase_07 AC 50 ms
4,376 KB
testcase_08 AC 342 ms
4,376 KB
testcase_09 AC 356 ms
4,380 KB
testcase_10 AC 171 ms
4,376 KB
testcase_11 AC 456 ms
4,376 KB
testcase_12 AC 138 ms
4,384 KB
testcase_13 AC 131 ms
4,376 KB
testcase_14 AC 21 ms
4,376 KB
testcase_15 AC 70 ms
4,376 KB
testcase_16 AC 125 ms
4,376 KB
testcase_17 AC 136 ms
4,376 KB
testcase_18 AC 88 ms
4,380 KB
testcase_19 AC 145 ms
4,380 KB
testcase_20 AC 58 ms
4,380 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 288 ms
4,376 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 WA -
testcase_42 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/all>
using ll = long long;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); ++i)
constexpr int inf = 2000'000'000;
constexpr ll linf = 4000000000000000000ll;
constexpr ll M7 = 1000000007ll;
constexpr ll M09 = 1000000009ll;
constexpr ll M9 = 998244353ll;
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
using namespace std;
using namespace atcoder;
template <typename T>
inline ostream& operator<<(ostream& os, vector<T>& v) {
    for (auto& e : v) os << e << " ";
    return os;
}
template <typename T, typename U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) noexcept {
    return os << "(" << p.first << ", " << p.second << ")";
}
#ifdef ONLINE_JUDGE
#define debug(...)
#else
#define debug(...) cerr << "<" << #__VA_ARGS__ << ">: ", debug_out(__VA_ARGS__)
template <typename T>
void debug_out(T t) {
    cerr << t << endl;
}
template <typename T, typename... Args>
void debug_out(T t, Args... args) {
    cerr << t << ", ";
    debug_out(args...);
}
#endif

ll modinv(ll a, ll M) {
    ll b = M, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= M;
    if (u < 0)
        u += M;
    return u;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, m, p, q;
    cin >> n >> m >> p >> q;
    rep(i, q) {
        ll x, f;
        cin >> x >> f;
        ll b = (f * modinv(x % p, p)) % p;
        if (b > m) {
            cout << 0 << "\n";
            continue;
        }
        if (f == 0) {
            cout << m / p + (m % p == 0) << "\n";
            continue;
        }
        cerr << b << endl;
        ll ans = (m - b) / p + 1;
        cout << ans << endl;
    }
    return 0;
}
0