# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
826102 |
2023-08-15T10:27:20 Z |
faruk |
Toys (CEOI18_toy) |
C++17 |
|
5000 ms |
5120 KB |
#include <bits/stdc++.h>
#define mp make_pair
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 1e6 + 2;
/*vector<int> min_prim(maxn);
vector<vector<int> > facs(maxn);
void sito() {
for (ll i = 1; i < maxn; i++) {
for (ll j = i; j < maxn; j += i)
facs[j].push_back(i);
}
}
*/
vector<int> min_prim(maxn);
void sito() {
for (ll i = 2; i < maxn; i++) {
if (min_prim[i] != 0)
continue;
for (ll j = i ; j < maxn; j += i)
if (min_prim[j] == 0)
min_prim[j] = i;
}
}
vector<int> facs;
void get_small_primes(int a) {
if (a == 1)
return;
facs.push_back(min_prim[a]);
get_small_primes(a / min_prim[a]);
}
vector<int> get_small_factors(int a) {
facs = vector<int>();
get_small_primes(a);
vector<int> factors;
factors.push_back(1);
vector<int> temp;
facs.push_back(1e9); int cnt = 0;
for (int i = 0; i < facs.size() - 1; i++) {
cnt++;
if (facs[i] != facs[i + 1]) {
int val = 1;
for (int j = 0; j < cnt; j++) {
val *= facs[i];
for (int a : factors)
temp.push_back(a * val);
}
factors.insert(factors.end(), all(temp));
temp.clear();
cnt = 0;
}
}
sort(all(factors));
return factors;
}
vector<int> factors;
vector<int> get_big_factors(int a, int l) {
for (int i = 1; i * i <= a and i <= l; i++) {
if (i * i == a)
factors.push_back(a);
else
{
factors.push_back(i);
if (a / i <= l)
factors.push_back(a/i);
}
}
sort(all(factors));
return factors;
}
vector<bool> there(maxn);
set<int> ans;
void recur(int n, int csum, int l) {
if (n == 1)
{
if (csum > maxn)
ans.insert(csum);
else {
if (there[csum])
return;
there[csum] = true;
}
return;
}
vector<int> factors;
if (n < maxn)
factors = get_small_factors(n);
else
factors = get_big_factors(n, l);
for (int i = 0; i < factors.size(); i++) { // the actual factor is a and left over is n/a
int a = factors.at(i);
if (a > l)
return;
if (a == 1)
continue;
recur(n/a, csum + a - 1, a);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
sito();
int n;
cin >> n;
recur(n, 0, n+1);
vector<int> anss;
for (int i = 0; i < maxn; i++)
if (there[i])
anss.push_back(i);
for (int a : ans)
anss.push_back(a);
cout << anss.size() << "\n";
for (int a : anss)
cout << a <<" ";
cout <<"\n";
}
Compilation message
toy.cpp: In function 'std::vector<int> get_small_factors(int)':
toy.cpp:48:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int i = 0; i < facs.size() - 1; i++) {
| ~~^~~~~~~~~~~~~~~~~
toy.cpp: In function 'void recur(int, int, int)':
toy.cpp:101:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
101 | for (int i = 0; i < factors.size(); i++) { // the actual factor is a and left over is n/a
| ~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4308 KB |
Output is correct |
2 |
Correct |
9 ms |
4308 KB |
Output is correct |
3 |
Correct |
9 ms |
4368 KB |
Output is correct |
4 |
Correct |
9 ms |
4308 KB |
Output is correct |
5 |
Correct |
9 ms |
4372 KB |
Output is correct |
6 |
Correct |
9 ms |
4308 KB |
Output is correct |
7 |
Correct |
10 ms |
4308 KB |
Output is correct |
8 |
Correct |
9 ms |
4308 KB |
Output is correct |
9 |
Correct |
9 ms |
4308 KB |
Output is correct |
10 |
Correct |
9 ms |
4368 KB |
Output is correct |
11 |
Correct |
8 ms |
4308 KB |
Output is correct |
12 |
Correct |
9 ms |
4308 KB |
Output is correct |
13 |
Correct |
9 ms |
4308 KB |
Output is correct |
14 |
Correct |
9 ms |
4308 KB |
Output is correct |
15 |
Correct |
9 ms |
4308 KB |
Output is correct |
16 |
Correct |
9 ms |
4368 KB |
Output is correct |
17 |
Correct |
9 ms |
4368 KB |
Output is correct |
18 |
Correct |
9 ms |
4308 KB |
Output is correct |
19 |
Correct |
9 ms |
4308 KB |
Output is correct |
20 |
Correct |
8 ms |
4308 KB |
Output is correct |
21 |
Correct |
9 ms |
4372 KB |
Output is correct |
22 |
Correct |
8 ms |
4372 KB |
Output is correct |
23 |
Correct |
9 ms |
4308 KB |
Output is correct |
24 |
Correct |
9 ms |
4368 KB |
Output is correct |
25 |
Correct |
9 ms |
4308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4308 KB |
Output is correct |
2 |
Correct |
9 ms |
4308 KB |
Output is correct |
3 |
Correct |
9 ms |
4368 KB |
Output is correct |
4 |
Correct |
9 ms |
4308 KB |
Output is correct |
5 |
Correct |
9 ms |
4372 KB |
Output is correct |
6 |
Correct |
9 ms |
4308 KB |
Output is correct |
7 |
Correct |
10 ms |
4308 KB |
Output is correct |
8 |
Correct |
9 ms |
4308 KB |
Output is correct |
9 |
Correct |
9 ms |
4308 KB |
Output is correct |
10 |
Correct |
9 ms |
4368 KB |
Output is correct |
11 |
Correct |
8 ms |
4308 KB |
Output is correct |
12 |
Correct |
9 ms |
4308 KB |
Output is correct |
13 |
Correct |
9 ms |
4308 KB |
Output is correct |
14 |
Correct |
9 ms |
4308 KB |
Output is correct |
15 |
Correct |
9 ms |
4308 KB |
Output is correct |
16 |
Correct |
9 ms |
4368 KB |
Output is correct |
17 |
Correct |
9 ms |
4368 KB |
Output is correct |
18 |
Correct |
9 ms |
4308 KB |
Output is correct |
19 |
Correct |
9 ms |
4308 KB |
Output is correct |
20 |
Correct |
8 ms |
4308 KB |
Output is correct |
21 |
Correct |
9 ms |
4372 KB |
Output is correct |
22 |
Correct |
8 ms |
4372 KB |
Output is correct |
23 |
Correct |
9 ms |
4308 KB |
Output is correct |
24 |
Correct |
9 ms |
4368 KB |
Output is correct |
25 |
Correct |
9 ms |
4308 KB |
Output is correct |
26 |
Correct |
9 ms |
4308 KB |
Output is correct |
27 |
Correct |
9 ms |
4308 KB |
Output is correct |
28 |
Correct |
9 ms |
4308 KB |
Output is correct |
29 |
Correct |
9 ms |
4308 KB |
Output is correct |
30 |
Correct |
9 ms |
4308 KB |
Output is correct |
31 |
Correct |
9 ms |
4308 KB |
Output is correct |
32 |
Correct |
10 ms |
4308 KB |
Output is correct |
33 |
Correct |
9 ms |
4308 KB |
Output is correct |
34 |
Correct |
9 ms |
4308 KB |
Output is correct |
35 |
Correct |
9 ms |
4308 KB |
Output is correct |
36 |
Correct |
9 ms |
4308 KB |
Output is correct |
37 |
Correct |
9 ms |
4308 KB |
Output is correct |
38 |
Correct |
9 ms |
4372 KB |
Output is correct |
39 |
Correct |
8 ms |
4308 KB |
Output is correct |
40 |
Correct |
9 ms |
4308 KB |
Output is correct |
41 |
Correct |
9 ms |
4308 KB |
Output is correct |
42 |
Correct |
9 ms |
4336 KB |
Output is correct |
43 |
Correct |
9 ms |
4364 KB |
Output is correct |
44 |
Correct |
9 ms |
4308 KB |
Output is correct |
45 |
Correct |
9 ms |
4308 KB |
Output is correct |
46 |
Correct |
9 ms |
4308 KB |
Output is correct |
47 |
Correct |
9 ms |
4308 KB |
Output is correct |
48 |
Correct |
9 ms |
4364 KB |
Output is correct |
49 |
Correct |
9 ms |
4364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4308 KB |
Output is correct |
2 |
Correct |
9 ms |
4308 KB |
Output is correct |
3 |
Correct |
9 ms |
4368 KB |
Output is correct |
4 |
Correct |
9 ms |
4308 KB |
Output is correct |
5 |
Correct |
9 ms |
4372 KB |
Output is correct |
6 |
Correct |
9 ms |
4308 KB |
Output is correct |
7 |
Correct |
10 ms |
4308 KB |
Output is correct |
8 |
Correct |
9 ms |
4308 KB |
Output is correct |
9 |
Correct |
9 ms |
4308 KB |
Output is correct |
10 |
Correct |
9 ms |
4368 KB |
Output is correct |
11 |
Correct |
8 ms |
4308 KB |
Output is correct |
12 |
Correct |
9 ms |
4308 KB |
Output is correct |
13 |
Correct |
9 ms |
4308 KB |
Output is correct |
14 |
Correct |
9 ms |
4308 KB |
Output is correct |
15 |
Correct |
9 ms |
4308 KB |
Output is correct |
16 |
Correct |
9 ms |
4368 KB |
Output is correct |
17 |
Correct |
9 ms |
4368 KB |
Output is correct |
18 |
Correct |
9 ms |
4308 KB |
Output is correct |
19 |
Correct |
9 ms |
4308 KB |
Output is correct |
20 |
Correct |
8 ms |
4308 KB |
Output is correct |
21 |
Correct |
9 ms |
4372 KB |
Output is correct |
22 |
Correct |
8 ms |
4372 KB |
Output is correct |
23 |
Correct |
9 ms |
4308 KB |
Output is correct |
24 |
Correct |
9 ms |
4368 KB |
Output is correct |
25 |
Correct |
9 ms |
4308 KB |
Output is correct |
26 |
Correct |
9 ms |
4308 KB |
Output is correct |
27 |
Correct |
9 ms |
4308 KB |
Output is correct |
28 |
Correct |
9 ms |
4308 KB |
Output is correct |
29 |
Correct |
9 ms |
4308 KB |
Output is correct |
30 |
Correct |
9 ms |
4308 KB |
Output is correct |
31 |
Correct |
9 ms |
4308 KB |
Output is correct |
32 |
Correct |
10 ms |
4308 KB |
Output is correct |
33 |
Correct |
9 ms |
4308 KB |
Output is correct |
34 |
Correct |
9 ms |
4308 KB |
Output is correct |
35 |
Correct |
9 ms |
4308 KB |
Output is correct |
36 |
Correct |
9 ms |
4308 KB |
Output is correct |
37 |
Correct |
9 ms |
4308 KB |
Output is correct |
38 |
Correct |
9 ms |
4372 KB |
Output is correct |
39 |
Correct |
8 ms |
4308 KB |
Output is correct |
40 |
Correct |
9 ms |
4308 KB |
Output is correct |
41 |
Correct |
9 ms |
4308 KB |
Output is correct |
42 |
Correct |
9 ms |
4336 KB |
Output is correct |
43 |
Correct |
9 ms |
4364 KB |
Output is correct |
44 |
Correct |
9 ms |
4308 KB |
Output is correct |
45 |
Correct |
9 ms |
4308 KB |
Output is correct |
46 |
Correct |
9 ms |
4308 KB |
Output is correct |
47 |
Correct |
9 ms |
4308 KB |
Output is correct |
48 |
Correct |
9 ms |
4364 KB |
Output is correct |
49 |
Correct |
9 ms |
4364 KB |
Output is correct |
50 |
Correct |
11 ms |
4308 KB |
Output is correct |
51 |
Correct |
10 ms |
4364 KB |
Output is correct |
52 |
Correct |
11 ms |
4372 KB |
Output is correct |
53 |
Correct |
10 ms |
4364 KB |
Output is correct |
54 |
Correct |
9 ms |
4308 KB |
Output is correct |
55 |
Correct |
12 ms |
4308 KB |
Output is correct |
56 |
Correct |
12 ms |
4384 KB |
Output is correct |
57 |
Correct |
11 ms |
4308 KB |
Output is correct |
58 |
Correct |
9 ms |
4308 KB |
Output is correct |
59 |
Correct |
9 ms |
4308 KB |
Output is correct |
60 |
Correct |
9 ms |
4308 KB |
Output is correct |
61 |
Correct |
10 ms |
4308 KB |
Output is correct |
62 |
Correct |
9 ms |
4368 KB |
Output is correct |
63 |
Correct |
9 ms |
4244 KB |
Output is correct |
64 |
Correct |
8 ms |
4308 KB |
Output is correct |
65 |
Correct |
10 ms |
4332 KB |
Output is correct |
66 |
Correct |
9 ms |
4308 KB |
Output is correct |
67 |
Correct |
9 ms |
4368 KB |
Output is correct |
68 |
Correct |
9 ms |
4368 KB |
Output is correct |
69 |
Correct |
9 ms |
4308 KB |
Output is correct |
70 |
Correct |
9 ms |
4364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4308 KB |
Output is correct |
2 |
Correct |
9 ms |
4308 KB |
Output is correct |
3 |
Correct |
9 ms |
4368 KB |
Output is correct |
4 |
Correct |
9 ms |
4308 KB |
Output is correct |
5 |
Correct |
9 ms |
4372 KB |
Output is correct |
6 |
Correct |
9 ms |
4308 KB |
Output is correct |
7 |
Correct |
10 ms |
4308 KB |
Output is correct |
8 |
Correct |
9 ms |
4308 KB |
Output is correct |
9 |
Correct |
9 ms |
4308 KB |
Output is correct |
10 |
Correct |
9 ms |
4368 KB |
Output is correct |
11 |
Correct |
8 ms |
4308 KB |
Output is correct |
12 |
Correct |
9 ms |
4308 KB |
Output is correct |
13 |
Correct |
9 ms |
4308 KB |
Output is correct |
14 |
Correct |
9 ms |
4308 KB |
Output is correct |
15 |
Correct |
9 ms |
4308 KB |
Output is correct |
16 |
Correct |
9 ms |
4368 KB |
Output is correct |
17 |
Correct |
9 ms |
4368 KB |
Output is correct |
18 |
Correct |
9 ms |
4308 KB |
Output is correct |
19 |
Correct |
9 ms |
4308 KB |
Output is correct |
20 |
Correct |
8 ms |
4308 KB |
Output is correct |
21 |
Correct |
9 ms |
4372 KB |
Output is correct |
22 |
Correct |
8 ms |
4372 KB |
Output is correct |
23 |
Correct |
9 ms |
4308 KB |
Output is correct |
24 |
Correct |
9 ms |
4368 KB |
Output is correct |
25 |
Correct |
9 ms |
4308 KB |
Output is correct |
26 |
Correct |
9 ms |
4308 KB |
Output is correct |
27 |
Correct |
9 ms |
4308 KB |
Output is correct |
28 |
Correct |
9 ms |
4308 KB |
Output is correct |
29 |
Correct |
9 ms |
4308 KB |
Output is correct |
30 |
Correct |
9 ms |
4308 KB |
Output is correct |
31 |
Correct |
9 ms |
4308 KB |
Output is correct |
32 |
Correct |
10 ms |
4308 KB |
Output is correct |
33 |
Correct |
9 ms |
4308 KB |
Output is correct |
34 |
Correct |
9 ms |
4308 KB |
Output is correct |
35 |
Correct |
9 ms |
4308 KB |
Output is correct |
36 |
Correct |
9 ms |
4308 KB |
Output is correct |
37 |
Correct |
9 ms |
4308 KB |
Output is correct |
38 |
Correct |
9 ms |
4372 KB |
Output is correct |
39 |
Correct |
8 ms |
4308 KB |
Output is correct |
40 |
Correct |
9 ms |
4308 KB |
Output is correct |
41 |
Correct |
9 ms |
4308 KB |
Output is correct |
42 |
Correct |
9 ms |
4336 KB |
Output is correct |
43 |
Correct |
9 ms |
4364 KB |
Output is correct |
44 |
Correct |
9 ms |
4308 KB |
Output is correct |
45 |
Correct |
9 ms |
4308 KB |
Output is correct |
46 |
Correct |
9 ms |
4308 KB |
Output is correct |
47 |
Correct |
9 ms |
4308 KB |
Output is correct |
48 |
Correct |
9 ms |
4364 KB |
Output is correct |
49 |
Correct |
9 ms |
4364 KB |
Output is correct |
50 |
Correct |
11 ms |
4308 KB |
Output is correct |
51 |
Correct |
10 ms |
4364 KB |
Output is correct |
52 |
Correct |
11 ms |
4372 KB |
Output is correct |
53 |
Correct |
10 ms |
4364 KB |
Output is correct |
54 |
Correct |
9 ms |
4308 KB |
Output is correct |
55 |
Correct |
12 ms |
4308 KB |
Output is correct |
56 |
Correct |
12 ms |
4384 KB |
Output is correct |
57 |
Correct |
11 ms |
4308 KB |
Output is correct |
58 |
Correct |
9 ms |
4308 KB |
Output is correct |
59 |
Correct |
9 ms |
4308 KB |
Output is correct |
60 |
Correct |
9 ms |
4308 KB |
Output is correct |
61 |
Correct |
10 ms |
4308 KB |
Output is correct |
62 |
Correct |
9 ms |
4368 KB |
Output is correct |
63 |
Correct |
9 ms |
4244 KB |
Output is correct |
64 |
Correct |
8 ms |
4308 KB |
Output is correct |
65 |
Correct |
10 ms |
4332 KB |
Output is correct |
66 |
Correct |
9 ms |
4308 KB |
Output is correct |
67 |
Correct |
9 ms |
4368 KB |
Output is correct |
68 |
Correct |
9 ms |
4368 KB |
Output is correct |
69 |
Correct |
9 ms |
4308 KB |
Output is correct |
70 |
Correct |
9 ms |
4364 KB |
Output is correct |
71 |
Execution timed out |
5038 ms |
5120 KB |
Time limit exceeded |
72 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4308 KB |
Output is correct |
2 |
Correct |
9 ms |
4308 KB |
Output is correct |
3 |
Correct |
9 ms |
4368 KB |
Output is correct |
4 |
Correct |
9 ms |
4308 KB |
Output is correct |
5 |
Correct |
9 ms |
4372 KB |
Output is correct |
6 |
Correct |
9 ms |
4308 KB |
Output is correct |
7 |
Correct |
10 ms |
4308 KB |
Output is correct |
8 |
Correct |
9 ms |
4308 KB |
Output is correct |
9 |
Correct |
9 ms |
4308 KB |
Output is correct |
10 |
Correct |
9 ms |
4368 KB |
Output is correct |
11 |
Correct |
8 ms |
4308 KB |
Output is correct |
12 |
Correct |
9 ms |
4308 KB |
Output is correct |
13 |
Correct |
9 ms |
4308 KB |
Output is correct |
14 |
Correct |
9 ms |
4308 KB |
Output is correct |
15 |
Correct |
9 ms |
4308 KB |
Output is correct |
16 |
Correct |
9 ms |
4368 KB |
Output is correct |
17 |
Correct |
9 ms |
4368 KB |
Output is correct |
18 |
Correct |
9 ms |
4308 KB |
Output is correct |
19 |
Correct |
9 ms |
4308 KB |
Output is correct |
20 |
Correct |
8 ms |
4308 KB |
Output is correct |
21 |
Correct |
9 ms |
4372 KB |
Output is correct |
22 |
Correct |
8 ms |
4372 KB |
Output is correct |
23 |
Correct |
9 ms |
4308 KB |
Output is correct |
24 |
Correct |
9 ms |
4368 KB |
Output is correct |
25 |
Correct |
9 ms |
4308 KB |
Output is correct |
26 |
Correct |
9 ms |
4308 KB |
Output is correct |
27 |
Correct |
9 ms |
4308 KB |
Output is correct |
28 |
Correct |
9 ms |
4308 KB |
Output is correct |
29 |
Correct |
9 ms |
4308 KB |
Output is correct |
30 |
Correct |
9 ms |
4308 KB |
Output is correct |
31 |
Correct |
9 ms |
4308 KB |
Output is correct |
32 |
Correct |
10 ms |
4308 KB |
Output is correct |
33 |
Correct |
9 ms |
4308 KB |
Output is correct |
34 |
Correct |
9 ms |
4308 KB |
Output is correct |
35 |
Correct |
9 ms |
4308 KB |
Output is correct |
36 |
Correct |
9 ms |
4308 KB |
Output is correct |
37 |
Correct |
9 ms |
4308 KB |
Output is correct |
38 |
Correct |
9 ms |
4372 KB |
Output is correct |
39 |
Correct |
8 ms |
4308 KB |
Output is correct |
40 |
Correct |
9 ms |
4308 KB |
Output is correct |
41 |
Correct |
9 ms |
4308 KB |
Output is correct |
42 |
Correct |
9 ms |
4336 KB |
Output is correct |
43 |
Correct |
9 ms |
4364 KB |
Output is correct |
44 |
Correct |
9 ms |
4308 KB |
Output is correct |
45 |
Correct |
9 ms |
4308 KB |
Output is correct |
46 |
Correct |
9 ms |
4308 KB |
Output is correct |
47 |
Correct |
9 ms |
4308 KB |
Output is correct |
48 |
Correct |
9 ms |
4364 KB |
Output is correct |
49 |
Correct |
9 ms |
4364 KB |
Output is correct |
50 |
Correct |
11 ms |
4308 KB |
Output is correct |
51 |
Correct |
10 ms |
4364 KB |
Output is correct |
52 |
Correct |
11 ms |
4372 KB |
Output is correct |
53 |
Correct |
10 ms |
4364 KB |
Output is correct |
54 |
Correct |
9 ms |
4308 KB |
Output is correct |
55 |
Correct |
12 ms |
4308 KB |
Output is correct |
56 |
Correct |
12 ms |
4384 KB |
Output is correct |
57 |
Correct |
11 ms |
4308 KB |
Output is correct |
58 |
Correct |
9 ms |
4308 KB |
Output is correct |
59 |
Correct |
9 ms |
4308 KB |
Output is correct |
60 |
Correct |
9 ms |
4308 KB |
Output is correct |
61 |
Correct |
10 ms |
4308 KB |
Output is correct |
62 |
Correct |
9 ms |
4368 KB |
Output is correct |
63 |
Correct |
9 ms |
4244 KB |
Output is correct |
64 |
Correct |
8 ms |
4308 KB |
Output is correct |
65 |
Correct |
10 ms |
4332 KB |
Output is correct |
66 |
Correct |
9 ms |
4308 KB |
Output is correct |
67 |
Correct |
9 ms |
4368 KB |
Output is correct |
68 |
Correct |
9 ms |
4368 KB |
Output is correct |
69 |
Correct |
9 ms |
4308 KB |
Output is correct |
70 |
Correct |
9 ms |
4364 KB |
Output is correct |
71 |
Execution timed out |
5038 ms |
5120 KB |
Time limit exceeded |
72 |
Halted |
0 ms |
0 KB |
- |