QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#347525 | #4634. Factor | ucup-team1209 | AC ✓ | 2451ms | 200004kb | C++20 | 2.2kb | 2024-03-09 14:08:21 | 2024-03-09 14:08:22 |
Judging History
answer
#include<bits/stdc++.h>
using std::cin;
using std::cout;
const int N = 3000005;
using ll = long long;
ll n;
ll sumd[N], maxsd[N], maxd[N];
bool is_pr[N];
ll pr[N], tot;
int min_id[N];
int bit[N];
inline void add(int x) {
for(;x;x &= x - 1) bit[x] += 1;
}
inline int qry(int x) {
int ans = 0;
for(;x <= tot;x += x & -x) ans += bit[x];
return ans;
}
inline void initpr(int p) {
memset(is_pr, 0, sizeof(is_pr));
p += 50;
for(int i = 2;i <= p;++i) if(!is_pr[i]) {
pr[++tot] = i;
for(int j = i;j <= p;j += i) {
is_pr[j] = 1;
if(!min_id[j]) min_id[j] = tot;
}
}
}
ll ans;
struct qy { int a, b; };
const int Z = 3e7;
qy mem[Z]; int cnt;
inline int cmp(const qy & x, const qy & y) {
return x.a < y.a;
}
inline void addq(int A, int B) {
mem[++cnt] = {A, B};
}
inline void dfs(ll x, int i, ll sx) {
ans += 1;
if(x <= n / sx) {
int R = std::upper_bound(pr + 1, pr + tot + 1, std::min(sx + 1, n / x)) - pr - 1;
for(int j = i + 1;j <= R;++j) {
ll p = pr[j];
if(n / x / p < p) {
ans += R - j + 1;
break;
}
ll mul = p, su = p + 1;
for(;x <= n / mul;su += mul *= p) {
dfs(x * mul, j, sx * su);
}
}
} else {
if(n / x >= pr[i + 1])
addq(n / x, i + 1);
}
}
int main() {
std::ios::sync_with_stdio(false), cin.tie(0);
cin >> n;
// std::cerr << double(clock()) / CLOCKS_PER_SEC << '\n';
const int m = sqrt(n) + 2;
sumd[1] = 1;
for(int i = 2;i <= m;++i) {
if(!is_pr[i]) {
ll su = 1;
for(ll j = i;j <= m;j *= i) {
su += j;
for(int k = j;k <= m;k += j) {
maxd[k] = i;
is_pr[k] = 1;
sumd[k] = su * sumd[k / j];
}
}
}
maxsd[i] = std::max(maxsd[i - 1], sumd[i]);
}
int lim = m;
for(;maxsd[n / lim] + 1 >= lim;) {
++ lim;
}
initpr(lim);
// std::cerr << double(clock()) / CLOCKS_PER_SEC << '\n';
dfs(1, 0, 1);
// std::cerr << double(clock()) / CLOCKS_PER_SEC << '\n';
std::sort(mem + 1, mem + cnt + 1, cmp);
// std::cerr << double(clock()) / CLOCKS_PER_SEC << '\n';
for(int i = 1, z = 2;i <= cnt;++i) {
const qy & x = mem[i];
for(;z <= x.a;++z) add(min_id[z]);
ans += qry(x.b);
}
// std::cerr << double(clock()) / CLOCKS_PER_SEC << '\n';
cout << ans << '\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 8576kb
input:
10
output:
5
result:
ok single line: '5'
Test #2:
score: 0
Accepted
time: 0ms
memory: 8644kb
input:
20
output:
9
result:
ok single line: '9'
Test #3:
score: 0
Accepted
time: 0ms
memory: 8584kb
input:
50
output:
17
result:
ok single line: '17'
Test #4:
score: 0
Accepted
time: 0ms
memory: 8660kb
input:
6
output:
4
result:
ok single line: '4'
Test #5:
score: 0
Accepted
time: 0ms
memory: 8636kb
input:
87
output:
26
result:
ok single line: '26'
Test #6:
score: 0
Accepted
time: 2ms
memory: 8632kb
input:
609
output:
130
result:
ok single line: '130'
Test #7:
score: 0
Accepted
time: 0ms
memory: 8664kb
input:
5126
output:
806
result:
ok single line: '806'
Test #8:
score: 0
Accepted
time: 0ms
memory: 8596kb
input:
92180
output:
10905
result:
ok single line: '10905'
Test #9:
score: 0
Accepted
time: 2ms
memory: 8712kb
input:
984096
output:
95960
result:
ok single line: '95960'
Test #10:
score: 0
Accepted
time: 3ms
memory: 8772kb
input:
5744387
output:
494209
result:
ok single line: '494209'
Test #11:
score: 0
Accepted
time: 2ms
memory: 8960kb
input:
51133311
output:
3851066
result:
ok single line: '3851066'
Test #12:
score: 0
Accepted
time: 13ms
memory: 10344kb
input:
607519174
output:
40319008
result:
ok single line: '40319008'
Test #13:
score: 0
Accepted
time: 80ms
memory: 17424kb
input:
7739876803
output:
456270136
result:
ok single line: '456270136'
Test #14:
score: 0
Accepted
time: 429ms
memory: 45720kb
input:
80754680817
output:
4304423738
result:
ok single line: '4304423738'
Test #15:
score: 0
Accepted
time: 2451ms
memory: 200004kb
input:
1000000000000
output:
48366248808
result:
ok single line: '48366248808'
Test #16:
score: 0
Accepted
time: 1086ms
memory: 96708kb
input:
300000000000
output:
15176932897
result:
ok single line: '15176932897'
Test #17:
score: 0
Accepted
time: 1521ms
memory: 130124kb
input:
500000000000
output:
24808936807
result:
ok single line: '24808936807'
Test #18:
score: 0
Accepted
time: 1846ms
memory: 161312kb
input:
700000000000
output:
34300642547
result:
ok single line: '34300642547'
Test #19:
score: 0
Accepted
time: 2086ms
memory: 173112kb
input:
790673894439
output:
38570752521
result:
ok single line: '38570752521'