結果

問題 No.1648 Sum of Powers
ユーザー siro53siro53
提出日時 2021-08-13 22:26:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,172 bytes
コンパイル時間 1,967 ms
コンパイル使用メモリ 207,156 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-03 20:02:31
合計ジャッジ時間 9,393 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,816 KB
testcase_01 AC 3 ms
6,820 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 3 ms
6,816 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 3 ms
6,820 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 AC 3 ms
6,820 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
g.cpp: In function 'int main()':
g.cpp:76:29: warning: 'A' is used uninitialized [-Wuninitialized]
g.cpp:75:8: note: 'A' was declared here
g.cpp:76:20: warning: 'P' is used uninitialized [-Wuninitialized]
g.cpp:75:14: note: 'P' was declared here
g.cpp:76:15: warning: 'Q' is used uninitialized [-Wuninitialized]
g.cpp:75:17: note: 'Q' was declared here
g.cpp:77:20: warning: 'B' is used uninitialized [-Wuninitialized]
g.cpp:75:11: note: 'B' was declared here

ソースコード

diff #

#line 1 "g.cpp"
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __Setup;

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define FOR(i, a, b) for(int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 998244353;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

void Case(int i) { cout << "Case #" << i << ": "; }
int popcount(int x) { return __builtin_popcount(x); }
ll popcount(ll x) { return __builtin_popcountll(x); }
#pragma endregion Macros

#line 1 "/home/siro53/kyo-pro/compro_library/math/pow_mod.hpp"
ll pow_mod(ll n, ll k, ll mod) {
    if(k == 0) {
        return 1;
    } else if(k % 2 == 1) {
        return pow_mod(n, k - 1, mod) * n % mod;
    } else {
        ll t = pow_mod(n, k / 2, mod);
        return t * t % mod;
    }
}
#line 1 "/home/siro53/kyo-pro/compro_library/math/BSGS.hpp"
// 与えられたx, y, pに対して、x^i=y(mod p)を満たす最小の正の整数iを返す
// 存在しない場合は-1
// O(√p log(p))
ll modlog(ll x, ll y, ll p) {
    ll H = sqrt(p) + 1;
    pair<ll, ll> baby[H];
    for(ll b = 0, xby = y; b < H; b++, xby = (xby * x) % p) {
        baby[b] = make_pair(xby, b);
    }
    sort(baby, baby + H);
    ll xH = 1;
    for(int i = 0; i < H; ++i) {
        xH = (xH * x) % p;
    }
    for(ll a = 1, xaH = xH; a <= H; a++, xaH = (xaH * xH) % p) {
        auto it = lower_bound(baby, baby + H, make_pair(xaH + 1, 0LL));
        if(it == baby) {
            continue;
        }
        it--;
        if(it->first == xaH) {
            return a * H - it->second;
        }
    }
    return -1;
}
#line 73 "g.cpp"

int main() {
    ll A, B, P, Q;
    ll y = (Q - (P * pow_mod(A, MOD-2, MOD) % MOD) + MOD) % MOD;
    ll res = modlog(B, y, MOD);
    assert(res != -1);
    res += 2;
    res %= (MOD-1);
    cout << res << endl;
}
0