#include <bits/stdc++.h>
using namespace std;
bool isPrime(int n)
{
// Corner cases
if (n <= 1) return false;
if (n <= 3) return true;
// This is checked so that we can skip
// middle five numbers in below loop
if (n%2 == 0 || n%3 == 0) return false;
for (int i=5; i*i<=n; i=i+6)
if (n%i == 0 || n%(i+2) == 0)
return false;
return true;
}
int p;
bool comp(int x, int y){
int xx = 0;
int yy = 0;
while(x % p == 0){
xx++;
x /= p;
}
while(y % p == 0){
yy++;
y /= p;
}
return xx < yy;
}
vector<vector<int> > adj;
vector<vector<int> > memo;
vector<int> factors;
int main(){
int n;
cin >> n;
vector<int> primes;
for(int i = 1;i <= min(n,100000);i++){
if(n % i == 0){
factors.push_back(i);
factors.push_back(n/i);
}
}
sort(factors.begin(),factors.end());
factors.erase(unique(factors.begin(),factors.end()),factors.end());
for(int x : factors){
if(isPrime(x)) primes.push_back(x);
}
for(int pp : primes){
p = pp;
stable_sort(factors.begin(),factors.end(),comp);
}
for(int i = 0;i < (int) factors.size();i++){
vector<int> v;
adj.push_back(v);
memo.push_back({});
//index[factors[i]] = i;
}
memo[0].push_back({0});
for(int i = 0;i < (int) factors.size();i++){
for(int j = i+1;j < (int) factors.size();j++){
int x = factors[i];
int y = factors[j];
if(y % x == 0){
int z = y / x;
if(true){
adj[j].push_back(i);
//cout << i << " " << j << "\n";
}
}
}
}
vector<int> answer = memo[0];
for(int i = 1;i < (int) factors.size();i++){
for(int j : adj[i]){
int c = factors[i] / factors[j] - 1;
for(int v : memo[j]){
memo[i].push_back(v + c);
}
}
answer = memo[i];
sort(answer.begin(),answer.end());
answer.erase(unique(answer.begin(),answer.end()),answer.end());
}
//sort(answer.begin(),answer.end());
//answer.erase(unique(answer.begin(),answer.end()),answer.end());
cout << answer.size() << "\n";
for(int x : answer){
cout << x << " ";
}
}
Compilation message
toy.cpp: In function 'int main()':
toy.cpp:76:9: warning: unused variable 'z' [-Wunused-variable]
int z = y / x;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
380 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
424 KB |
Output is correct |
21 |
Correct |
2 ms |
256 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
380 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
424 KB |
Output is correct |
21 |
Correct |
2 ms |
256 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
760 KB |
Output is correct |
27 |
Correct |
4 ms |
632 KB |
Output is correct |
28 |
Correct |
3 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
10 ms |
1524 KB |
Output is correct |
32 |
Correct |
6 ms |
1016 KB |
Output is correct |
33 |
Correct |
5 ms |
764 KB |
Output is correct |
34 |
Correct |
2 ms |
256 KB |
Output is correct |
35 |
Correct |
2 ms |
256 KB |
Output is correct |
36 |
Correct |
3 ms |
376 KB |
Output is correct |
37 |
Correct |
5 ms |
836 KB |
Output is correct |
38 |
Correct |
2 ms |
376 KB |
Output is correct |
39 |
Correct |
2 ms |
256 KB |
Output is correct |
40 |
Correct |
4 ms |
632 KB |
Output is correct |
41 |
Correct |
2 ms |
376 KB |
Output is correct |
42 |
Correct |
2 ms |
256 KB |
Output is correct |
43 |
Correct |
2 ms |
376 KB |
Output is correct |
44 |
Correct |
2 ms |
256 KB |
Output is correct |
45 |
Correct |
2 ms |
376 KB |
Output is correct |
46 |
Correct |
2 ms |
376 KB |
Output is correct |
47 |
Correct |
4 ms |
632 KB |
Output is correct |
48 |
Correct |
2 ms |
376 KB |
Output is correct |
49 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
380 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
424 KB |
Output is correct |
21 |
Correct |
2 ms |
256 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
760 KB |
Output is correct |
27 |
Correct |
4 ms |
632 KB |
Output is correct |
28 |
Correct |
3 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
10 ms |
1524 KB |
Output is correct |
32 |
Correct |
6 ms |
1016 KB |
Output is correct |
33 |
Correct |
5 ms |
764 KB |
Output is correct |
34 |
Correct |
2 ms |
256 KB |
Output is correct |
35 |
Correct |
2 ms |
256 KB |
Output is correct |
36 |
Correct |
3 ms |
376 KB |
Output is correct |
37 |
Correct |
5 ms |
836 KB |
Output is correct |
38 |
Correct |
2 ms |
376 KB |
Output is correct |
39 |
Correct |
2 ms |
256 KB |
Output is correct |
40 |
Correct |
4 ms |
632 KB |
Output is correct |
41 |
Correct |
2 ms |
376 KB |
Output is correct |
42 |
Correct |
2 ms |
256 KB |
Output is correct |
43 |
Correct |
2 ms |
376 KB |
Output is correct |
44 |
Correct |
2 ms |
256 KB |
Output is correct |
45 |
Correct |
2 ms |
376 KB |
Output is correct |
46 |
Correct |
2 ms |
376 KB |
Output is correct |
47 |
Correct |
4 ms |
632 KB |
Output is correct |
48 |
Correct |
2 ms |
376 KB |
Output is correct |
49 |
Correct |
2 ms |
376 KB |
Output is correct |
50 |
Correct |
38 ms |
4584 KB |
Output is correct |
51 |
Correct |
31 ms |
3928 KB |
Output is correct |
52 |
Correct |
55 ms |
6684 KB |
Output is correct |
53 |
Correct |
46 ms |
6156 KB |
Output is correct |
54 |
Correct |
19 ms |
1392 KB |
Output is correct |
55 |
Correct |
174 ms |
21928 KB |
Output is correct |
56 |
Correct |
192 ms |
26408 KB |
Output is correct |
57 |
Correct |
83 ms |
10568 KB |
Output is correct |
58 |
Correct |
3 ms |
256 KB |
Output is correct |
59 |
Correct |
3 ms |
256 KB |
Output is correct |
60 |
Correct |
6 ms |
1016 KB |
Output is correct |
61 |
Correct |
107 ms |
14504 KB |
Output is correct |
62 |
Correct |
9 ms |
1592 KB |
Output is correct |
63 |
Correct |
5 ms |
764 KB |
Output is correct |
64 |
Correct |
3 ms |
256 KB |
Output is correct |
65 |
Correct |
28 ms |
3304 KB |
Output is correct |
66 |
Correct |
3 ms |
376 KB |
Output is correct |
67 |
Correct |
3 ms |
256 KB |
Output is correct |
68 |
Correct |
3 ms |
376 KB |
Output is correct |
69 |
Correct |
3 ms |
376 KB |
Output is correct |
70 |
Correct |
6 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
380 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
424 KB |
Output is correct |
21 |
Correct |
2 ms |
256 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
760 KB |
Output is correct |
27 |
Correct |
4 ms |
632 KB |
Output is correct |
28 |
Correct |
3 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
10 ms |
1524 KB |
Output is correct |
32 |
Correct |
6 ms |
1016 KB |
Output is correct |
33 |
Correct |
5 ms |
764 KB |
Output is correct |
34 |
Correct |
2 ms |
256 KB |
Output is correct |
35 |
Correct |
2 ms |
256 KB |
Output is correct |
36 |
Correct |
3 ms |
376 KB |
Output is correct |
37 |
Correct |
5 ms |
836 KB |
Output is correct |
38 |
Correct |
2 ms |
376 KB |
Output is correct |
39 |
Correct |
2 ms |
256 KB |
Output is correct |
40 |
Correct |
4 ms |
632 KB |
Output is correct |
41 |
Correct |
2 ms |
376 KB |
Output is correct |
42 |
Correct |
2 ms |
256 KB |
Output is correct |
43 |
Correct |
2 ms |
376 KB |
Output is correct |
44 |
Correct |
2 ms |
256 KB |
Output is correct |
45 |
Correct |
2 ms |
376 KB |
Output is correct |
46 |
Correct |
2 ms |
376 KB |
Output is correct |
47 |
Correct |
4 ms |
632 KB |
Output is correct |
48 |
Correct |
2 ms |
376 KB |
Output is correct |
49 |
Correct |
2 ms |
376 KB |
Output is correct |
50 |
Correct |
38 ms |
4584 KB |
Output is correct |
51 |
Correct |
31 ms |
3928 KB |
Output is correct |
52 |
Correct |
55 ms |
6684 KB |
Output is correct |
53 |
Correct |
46 ms |
6156 KB |
Output is correct |
54 |
Correct |
19 ms |
1392 KB |
Output is correct |
55 |
Correct |
174 ms |
21928 KB |
Output is correct |
56 |
Correct |
192 ms |
26408 KB |
Output is correct |
57 |
Correct |
83 ms |
10568 KB |
Output is correct |
58 |
Correct |
3 ms |
256 KB |
Output is correct |
59 |
Correct |
3 ms |
256 KB |
Output is correct |
60 |
Correct |
6 ms |
1016 KB |
Output is correct |
61 |
Correct |
107 ms |
14504 KB |
Output is correct |
62 |
Correct |
9 ms |
1592 KB |
Output is correct |
63 |
Correct |
5 ms |
764 KB |
Output is correct |
64 |
Correct |
3 ms |
256 KB |
Output is correct |
65 |
Correct |
28 ms |
3304 KB |
Output is correct |
66 |
Correct |
3 ms |
376 KB |
Output is correct |
67 |
Correct |
3 ms |
256 KB |
Output is correct |
68 |
Correct |
3 ms |
376 KB |
Output is correct |
69 |
Correct |
3 ms |
376 KB |
Output is correct |
70 |
Correct |
6 ms |
760 KB |
Output is correct |
71 |
Runtime error |
2638 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
72 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
380 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
424 KB |
Output is correct |
21 |
Correct |
2 ms |
256 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
760 KB |
Output is correct |
27 |
Correct |
4 ms |
632 KB |
Output is correct |
28 |
Correct |
3 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
10 ms |
1524 KB |
Output is correct |
32 |
Correct |
6 ms |
1016 KB |
Output is correct |
33 |
Correct |
5 ms |
764 KB |
Output is correct |
34 |
Correct |
2 ms |
256 KB |
Output is correct |
35 |
Correct |
2 ms |
256 KB |
Output is correct |
36 |
Correct |
3 ms |
376 KB |
Output is correct |
37 |
Correct |
5 ms |
836 KB |
Output is correct |
38 |
Correct |
2 ms |
376 KB |
Output is correct |
39 |
Correct |
2 ms |
256 KB |
Output is correct |
40 |
Correct |
4 ms |
632 KB |
Output is correct |
41 |
Correct |
2 ms |
376 KB |
Output is correct |
42 |
Correct |
2 ms |
256 KB |
Output is correct |
43 |
Correct |
2 ms |
376 KB |
Output is correct |
44 |
Correct |
2 ms |
256 KB |
Output is correct |
45 |
Correct |
2 ms |
376 KB |
Output is correct |
46 |
Correct |
2 ms |
376 KB |
Output is correct |
47 |
Correct |
4 ms |
632 KB |
Output is correct |
48 |
Correct |
2 ms |
376 KB |
Output is correct |
49 |
Correct |
2 ms |
376 KB |
Output is correct |
50 |
Correct |
38 ms |
4584 KB |
Output is correct |
51 |
Correct |
31 ms |
3928 KB |
Output is correct |
52 |
Correct |
55 ms |
6684 KB |
Output is correct |
53 |
Correct |
46 ms |
6156 KB |
Output is correct |
54 |
Correct |
19 ms |
1392 KB |
Output is correct |
55 |
Correct |
174 ms |
21928 KB |
Output is correct |
56 |
Correct |
192 ms |
26408 KB |
Output is correct |
57 |
Correct |
83 ms |
10568 KB |
Output is correct |
58 |
Correct |
3 ms |
256 KB |
Output is correct |
59 |
Correct |
3 ms |
256 KB |
Output is correct |
60 |
Correct |
6 ms |
1016 KB |
Output is correct |
61 |
Correct |
107 ms |
14504 KB |
Output is correct |
62 |
Correct |
9 ms |
1592 KB |
Output is correct |
63 |
Correct |
5 ms |
764 KB |
Output is correct |
64 |
Correct |
3 ms |
256 KB |
Output is correct |
65 |
Correct |
28 ms |
3304 KB |
Output is correct |
66 |
Correct |
3 ms |
376 KB |
Output is correct |
67 |
Correct |
3 ms |
256 KB |
Output is correct |
68 |
Correct |
3 ms |
376 KB |
Output is correct |
69 |
Correct |
3 ms |
376 KB |
Output is correct |
70 |
Correct |
6 ms |
760 KB |
Output is correct |
71 |
Runtime error |
2638 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
72 |
Halted |
0 ms |
0 KB |
- |