QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#345262 | #3415. Exponential Towers | PetroTarnavskyi# | AC ✓ | 5ms | 4380kb | C++20 | 1.9kb | 2024-03-06 18:26:31 | 2024-03-06 18:26:31 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
int a[3];
string s;
bool read()
{
if(!(cin >> s))
return false;
s += "^";
int prev = 0;
int pos = 0;
FOR(i, 0, SZ(s))
{
if(s[i] == '^')
{
//cerr << s << " " << pos << " " << prev << " " << i << "\n";
a[pos] = stoi(s.substr(prev, i - prev));
pos++;
prev = i + 1;
continue;
}
}
return true;
}
vector<PII> factor(int x)
{
vector<PII> res;
for(int p = 2; p * p <= x; p++)
{
if(x % p)
continue;
int cnt = 0;
while(x % p == 0)
{
x /= p;
cnt++;
}
res.PB({p, cnt});
}
if(x != 1)
res.PB({x, 1});
return res;
}
const int N = 2e5;
int f[N];
void init()
{
FOR(b, 2, N)
{
FOR(x, 2, N)
{
LL pw = 1;
FOR(i, 0, b)
{
pw *= x;
if(pw >= N)
break;
}
if(pw >= N)
{
break;
}
f[pw] += f[b] + 1;
}
}
}
void solve()
{
auto A = factor(a[0]);
int k = 0;
for(auto [p, c] : A)
k = gcd(k, c);
map<int, int> cnt;
auto B = factor(a[1]);
auto K = factor(k);
for(auto [p, c] : B)
cnt[p] += a[2] * c;
for(auto [p, c] : K)
cnt[p] += c;
int mx = 0;
for(auto [p, c] : cnt)
mx = max(mx, c);
LL ans = 0;
FOR(c1, 2, mx + 1)
{
LL num = 1;
for(auto [p, c] : cnt)
num *= (c / c1 + 1);
num -= 1;
ans += num * (f[c1] + 1);
}
cout << ans << "\n";
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
init();
while(read())
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 5ms
memory: 4380kb
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: 2ms
memory: 4376kb
input:
8192^13^2
output:
2
result:
ok single line: '2'
Test #3:
score: 0
Accepted
time: 3ms
memory: 4376kb
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: 2ms
memory: 4272kb
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