QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#298168 | #4634. Factor | defyers | AC ✓ | 656ms | 35632kb | C++14 | 1.4kb | 2024-01-05 19:12:34 | 2024-01-05 19:12:34 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define LL long long
vector<int> prime;
void find_prime(int n) {
vector<int> lp(n, 0);
for (int i = 2; i <= n; i++) {
if (lp[i] == 0) { lp[i] = i; prime.push_back(i); }
for (int j = 0; i * prime[j] <= n; j++) {
lp[i * prime[j]] = prime[j];
if (prime[j] == lp[i]) break; } } return;
}
LL n;
LL ans;
LL toprime[4000005];
LL cal(int p, LL sum) {
sum = min(sum, (LL)4e6);
if (toprime[sum] < p) return 0;
return toprime[sum] - p + 1;
}
void f(LL sum, LL num, int pl) {
ans += cal(pl, min(sum + 1, num));
if (num < prime[pl] * prime[pl]) return;
for (int i = pl; i < prime.size(); i++) {
if (num < prime[i] * prime[i] || sum + 1 < prime[i]) break;
LL tmp = prime[i];
LL add = 1 + prime[i];
while (tmp <= num) {
if (tmp != prime[i]) ans++;
f(min((LL)1e7, sum * add), num / tmp, i + 1);
tmp *= prime[i];
add += tmp;
add = min(add, (LL)1e7);
}
}
}
void solve() {
cin >> n;
ans = 1;
f(1, n, 0);
cout << ans << "\n";
return;
}
int main() {
ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
cout << fixed << setprecision(10);
find_prime(3e6);
int p = 0;
for (int i = 2; i <= 4e6; i++) {
while (p < prime.size() && prime[p + 1] <= i) p++;
toprime[i] = p;
}
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 15ms
memory: 35440kb
input:
10
output:
5
result:
ok single line: '5'
Test #2:
score: 0
Accepted
time: 11ms
memory: 35124kb
input:
20
output:
9
result:
ok single line: '9'
Test #3:
score: 0
Accepted
time: 15ms
memory: 35252kb
input:
50
output:
17
result:
ok single line: '17'
Test #4:
score: 0
Accepted
time: 20ms
memory: 35540kb
input:
6
output:
4
result:
ok single line: '4'
Test #5:
score: 0
Accepted
time: 16ms
memory: 35352kb
input:
87
output:
26
result:
ok single line: '26'
Test #6:
score: 0
Accepted
time: 11ms
memory: 35396kb
input:
609
output:
130
result:
ok single line: '130'
Test #7:
score: 0
Accepted
time: 19ms
memory: 35188kb
input:
5126
output:
806
result:
ok single line: '806'
Test #8:
score: 0
Accepted
time: 12ms
memory: 35628kb
input:
92180
output:
10905
result:
ok single line: '10905'
Test #9:
score: 0
Accepted
time: 24ms
memory: 35356kb
input:
984096
output:
95960
result:
ok single line: '95960'
Test #10:
score: 0
Accepted
time: 20ms
memory: 35460kb
input:
5744387
output:
494209
result:
ok single line: '494209'
Test #11:
score: 0
Accepted
time: 22ms
memory: 35200kb
input:
51133311
output:
3851066
result:
ok single line: '3851066'
Test #12:
score: 0
Accepted
time: 21ms
memory: 35632kb
input:
607519174
output:
40319008
result:
ok single line: '40319008'
Test #13:
score: 0
Accepted
time: 31ms
memory: 35168kb
input:
7739876803
output:
456270136
result:
ok single line: '456270136'
Test #14:
score: 0
Accepted
time: 117ms
memory: 35524kb
input:
80754680817
output:
4304423738
result:
ok single line: '4304423738'
Test #15:
score: 0
Accepted
time: 656ms
memory: 35272kb
input:
1000000000000
output:
48366248808
result:
ok single line: '48366248808'
Test #16:
score: 0
Accepted
time: 282ms
memory: 35340kb
input:
300000000000
output:
15176932897
result:
ok single line: '15176932897'
Test #17:
score: 0
Accepted
time: 403ms
memory: 35200kb
input:
500000000000
output:
24808936807
result:
ok single line: '24808936807'
Test #18:
score: 0
Accepted
time: 514ms
memory: 35156kb
input:
700000000000
output:
34300642547
result:
ok single line: '34300642547'
Test #19:
score: 0
Accepted
time: 554ms
memory: 35404kb
input:
790673894439
output:
38570752521
result:
ok single line: '38570752521'