QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#834343#3415. Exponential TowersSGColin#AC ✓39ms7772kbC++201.9kb2024-12-27 15:46:242024-12-27 15:46:24

Judging History

你现在查看的是最新测评结果

  • [2024-12-27 15:46:24]
  • 评测
  • 测评结果:AC
  • 用时:39ms
  • 内存:7772kb
  • [2024-12-27 15:46:24]
  • 提交

answer

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

typedef long long ll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tii;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define all(s) (s).begin(), (s).end()
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)

constexpr int N = 200007;

int npw[N];

string s;

int gcd(int a, int b) {return b ? gcd(b, a % b) : a;}

inline void work() {
    int a = 0, b = 0, c = 0;
    int ptr = 0;
    for (; s[ptr] != '^'; ++ptr) a = a * 10 + (s[ptr] - '0');
    ++ptr;
    for (; s[ptr] != '^'; ++ptr) b = b * 10 + (s[ptr] - '0');
    ++ptr;
    for (; ptr < s.size(); ++ptr) c = c * 10 + (s[ptr] - '0');
    auto decomp = [&](int x) {
        vector<pii> ret;
        for (int i = 2; i <= x; ++i)
            if (x % i == 0) {
                int num = 0;
                while (x % i == 0) {++num; x /= i;}
                ret.eb(i, num);
            }
        return ret;
    };
    auto da = decomp(a);
    int k = 0;
    for (auto [w, cnt] : da) k = gcd(k, cnt);
    map<int, int> num;
    auto dk = decomp(k);
    for (auto [w, cnt] : dk) num[w] = cnt;
    auto db = decomp(b);
    for (auto [w, cnt] : db) num[w] += cnt * c;
    ll ANS = 0;
    rep(cc, 2, N - 1) {
        ll ans = 1;
        for (auto [w, cnt] : num) ans = ans * ((cnt / cc) + 1);
        ANS += 1ll * (ans - 1) * npw[cc];
    }
    printf("%lld\n", ANS);
}

vector<pii> rts[N];

int main() {
    for (int i = 2; i < N; ++i) {
        ll nw = 1ll * i * i;
        for (int j = 2; nw < N; ++j) {
            rts[nw].eb(i, j);
            nw = nw * i;
        }
        npw[i] = 1;
        for (auto [rt, k] : rts[i]) npw[i] += npw[k];
    }
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (cin >> s) work();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 39ms
memory: 7772kb

input:

9585^9585^9585
9240^9240^9240
9551^9551^9551
9583^9583^9583
2^2^9585
256^2^2
2^8640^2
2401^7200^2
4096^7200^2
14^9240^9585
25^9240^9585
6561^9240^9585
2401^2^9585
256^9585^9585
8264^1976^1870
4705^837^2740
610^5139^8291
3901^17^8330
8294^6233^9033
6133^3634^2358
3755^7598^6716
7898^9570^5193
587^784...

output:

586634281353
7677363845492302798
89655
138628311
90017
6
101
123
126
9217651263554787837
9218249112877874830
9218887719880762148
90021
1014853296051
4367088281
17039192
103785131
77074
61614682
2919333595
67305155678
143524704136644229
179594998873
176153579169

result:

ok 24 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 6288kb

input:

8192^13^2

output:

2

result:

ok single line: '2'

Test #3:

score: 0
Accepted
time: 7ms
memory: 6564kb

input:

4^2^2
8^12^2
8192^8192^8192
2^900^576

output:

2
10
1258112
342025379

result:

ok 4 lines

Test #4:

score: 0
Accepted
time: 38ms
memory: 6576kb

input:

4^2^2
8^12^2
8192^8192^8192
2^900^576
4096^9240^9585
5^6561^8192
2^2^2
3^3^3
4^4^4
5^5^5
2^3^5
16^16^16
144^144^144
8192^8192^8192
16^18^2
256^2^9585
256^8192^9585
90^900^9000
32^6006^8888
32^6006^8889
10^1800^10
2^2^2
2^2^3
2^2^4
2^2^5
2^2^6
2^2^7
2^2^8
8192^2310^9585

output:

2
10
1258112
342025379
9219832368275505910
742330
1
2
18
6
6
280
128607
1258112
17
90045
1491686
1295018330307
2107560797045868526
2107946443866572119
3658
1
2
5
6
9
10
15
3072859342112467367

result:

ok 29 lines