結果

問題 No.1931 Fraction 2
ユーザー ぷらぷら
提出日時 2022-04-29 14:41:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 243 ms / 2,000 ms
コード長 3,130 bytes
コンパイル時間 2,689 ms
コンパイル使用メモリ 215,508 KB
実行使用メモリ 16,140 KB
最終ジャッジ日時 2023-09-20 22:30:19
合計ジャッジ時間 9,908 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
8,528 KB
testcase_01 AC 6 ms
8,468 KB
testcase_02 AC 5 ms
8,476 KB
testcase_03 AC 6 ms
8,620 KB
testcase_04 AC 7 ms
8,464 KB
testcase_05 AC 6 ms
8,476 KB
testcase_06 AC 7 ms
8,584 KB
testcase_07 AC 7 ms
8,516 KB
testcase_08 AC 6 ms
8,544 KB
testcase_09 AC 7 ms
8,488 KB
testcase_10 AC 6 ms
8,512 KB
testcase_11 AC 6 ms
8,600 KB
testcase_12 AC 7 ms
8,484 KB
testcase_13 AC 48 ms
10,068 KB
testcase_14 AC 155 ms
13,144 KB
testcase_15 AC 72 ms
11,048 KB
testcase_16 AC 18 ms
9,076 KB
testcase_17 AC 22 ms
9,192 KB
testcase_18 AC 211 ms
15,340 KB
testcase_19 AC 211 ms
15,156 KB
testcase_20 AC 211 ms
15,168 KB
testcase_21 AC 216 ms
15,332 KB
testcase_22 AC 212 ms
15,100 KB
testcase_23 AC 215 ms
15,308 KB
testcase_24 AC 213 ms
15,068 KB
testcase_25 AC 211 ms
15,256 KB
testcase_26 AC 215 ms
15,168 KB
testcase_27 AC 212 ms
15,092 KB
testcase_28 AC 239 ms
15,940 KB
testcase_29 AC 237 ms
15,828 KB
testcase_30 AC 240 ms
16,064 KB
testcase_31 AC 239 ms
15,832 KB
testcase_32 AC 236 ms
15,924 KB
testcase_33 AC 237 ms
16,140 KB
testcase_34 AC 238 ms
15,920 KB
testcase_35 AC 243 ms
15,984 KB
testcase_36 AC 237 ms
15,872 KB
testcase_37 AC 237 ms
15,872 KB
testcase_38 AC 6 ms
8,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr int mod = 998244353;

long long modpow(long long a,long long b) {
    long long ans = 1;
    while(b) {
        if(b & 1) {
            (ans *= a) %= mod;
        }
        (a *= a) %= mod;
        b /= 2;
    }
    return ans;
}

long long modpow(long long a,long long b,long long m) {
    long long ans = 1;
    while(b) {
        if(b & 1) {
            (ans *= a) %= m;
        }
        (a *= a) %= m;
        b /= 2;
    }
    return ans;
}

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

struct primenumber {
    vector<int> spf;
    primenumber(int N) {
        init(N);
    }
    void init(int N) {
        spf.assign(N+1,0);
        for(int i = 0; i <= N; i++) {
            spf[i] = i;
        }
        for(int i = 2; i*i <= N; i++) {
            if(spf[i] == i) {
                for(int j = i*i; j <= N; j += i) {
                    if(spf[j] == j) {
                        spf[j] = i;
                    }
                }
            }
        }
    }
    bool is_prime(long long n) {
        bool flag = true;
        if(n == 1) {
            flag = false;
        }
        for(long long i = 2; i*i <= n; i++) {
            if(n%i == 0) {
                flag = false;
                break;
            }
        }
        return flag;
    }
    map<int,int> get(int n) {
        map<int,int> m;
        while(n != 1) {
            m[spf[n]]++;
            n /= spf[n];
        }
        return m;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<int>A(N),B(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i] >> B[i];
    }
    primenumber zz(200000);
    vector<vector<pair<int,int>>>pura(200001);
    for(int i = 0; i < N; i++) {
        for(auto j:zz.get(B[i])) {
            pura[j.first].push_back({j.second,i});
        }
    }
    long long d = 1;
    for(int i = 2; i <= 200000; i++) {
        if(pura[i].empty()) {
            continue;
        }
        int mx = 0;
        for(int j = 0; j < pura[i].size(); j++) {
            mx = max(mx,pura[i][j].first);
        }
        int cnt = 0;
        vector<long long>tmp(mx);
        long long gyaku = modpow(i,mx);
        for(int j = 0; j < pura[i].size(); j++) {
            tmp[mx-pura[i][j].first] += A[pura[i][j].second]*modinv(B[pura[i][j].second]/modpow(i,pura[i][j].first),gyaku);
        }
        long long sum = 0;
        for(int j = 0; j < mx; j++) {
            sum += tmp[j];
            if(sum%i == 0) {
                sum /= i;
                cnt++;
            }
            else {
                break;
            }
        }
        d *= modpow(i,mx-cnt);
        d %= mod;
    }
    int c = 0;
    for(int i = 0; i < N; i++) {
        c += A[i]*d%mod*modpow(B[i],mod-2)%mod;
        if(c >= mod) {
            c -= mod;
        }
    }
    cout << c << " " << d << endl;
}
0