QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#298142 | #4634. Factor | defyers# | TL | 2057ms | 15920kb | C++14 | 1.0kb | 2024-01-05 18:31:02 | 2024-01-05 18:31:03 |
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 = 0;
void f(LL sum, LL num, int pl) {
ans++;
//cout << "num=" << num << endl;
for (int i = pl; i < prime.size(); i++) {
if (prime[i] * num > n || sum + 1 < prime[i]) break;
LL tmp = prime[i];
LL add = 1 + prime[i];
while (tmp * num <= n) {
f(min((LL)1e7, sum * add), tmp * num, i + 1);
tmp *= prime[i];
add += tmp;
add = min(add, (LL)1e7);
}
}
}
void solve() {
cin >> n;
f(1, 1, 0); // prime[0] = 2
cout << ans << "\n";
return;
}
int main() {
ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
cout << fixed << setprecision(10);
find_prime(3e6);
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 7ms
memory: 15872kb
input:
10
output:
5
result:
ok single line: '5'
Test #2:
score: 0
Accepted
time: 11ms
memory: 15916kb
input:
20
output:
9
result:
ok single line: '9'
Test #3:
score: 0
Accepted
time: 9ms
memory: 15876kb
input:
50
output:
17
result:
ok single line: '17'
Test #4:
score: 0
Accepted
time: 11ms
memory: 15908kb
input:
6
output:
4
result:
ok single line: '4'
Test #5:
score: 0
Accepted
time: 11ms
memory: 15848kb
input:
87
output:
26
result:
ok single line: '26'
Test #6:
score: 0
Accepted
time: 7ms
memory: 15872kb
input:
609
output:
130
result:
ok single line: '130'
Test #7:
score: 0
Accepted
time: 15ms
memory: 15828kb
input:
5126
output:
806
result:
ok single line: '806'
Test #8:
score: 0
Accepted
time: 11ms
memory: 15864kb
input:
92180
output:
10905
result:
ok single line: '10905'
Test #9:
score: 0
Accepted
time: 12ms
memory: 15920kb
input:
984096
output:
95960
result:
ok single line: '95960'
Test #10:
score: 0
Accepted
time: 11ms
memory: 15832kb
input:
5744387
output:
494209
result:
ok single line: '494209'
Test #11:
score: 0
Accepted
time: 44ms
memory: 15744kb
input:
51133311
output:
3851066
result:
ok single line: '3851066'
Test #12:
score: 0
Accepted
time: 201ms
memory: 15868kb
input:
607519174
output:
40319008
result:
ok single line: '40319008'
Test #13:
score: 0
Accepted
time: 2057ms
memory: 15808kb
input:
7739876803
output:
456270136
result:
ok single line: '456270136'
Test #14:
score: -100
Time Limit Exceeded
input:
80754680817