#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <map>
#include <cassert>
using namespace std;
#define sz(x) (int(x.size()))
using vi = vector<int>;
using ll = long long;
// map< int, vector<int> > res;
vi sf;
long long n;
vector<int> res[40'000]; //i*i <= n
vector<int> res2[40'000]; //i*i >= n, access n/i.
vi solved(1+40'000, 0);
vi solved2(1+40'000, 0);
vector<int> factors[40'000];
vector<int> factors2[40'000];
vi visited(1+40'000, 0);
vi visited2(1+40'000, 0);
vi vis(1+40'000, 0);
vi vis2(1+40'000, 0);
vector<int>& get_res(long long u)
{
if(u*u <= n) return res[u];
else return res2[n/u];
}
vector<int>& get_factors(long long u)
{
if(u*u <= n) return factors[u];
else return factors2[n/u];
}
int& get_solved(long long u)
{
if(u*u <= n) return solved[u];
else return solved2[n/u];
}
int& get_visited(long long u)
{
if(u*u <= n) return visited[u];
else return visited2[n/u];
}
int& get_vis(long long u)
{
if(u*u <= n) return vis[u];
else return vis[n/u];
}
void solve(long long i)
{
if(get_solved(i)) return;
else get_solved(i) = 1;
vi ans(1, i-1);
for(ll j: get_factors(i))
{
// cerr << "j = " << j << '\n';
if(j >= i || j*j > i) break;
// cerr << i << " -> " << j << '\n';
long long u = j;
long long v = i/j;
solve(u);
solve(v);
for(int a: get_res(u))
{
if(get_visited(a) == 1) continue;
get_visited(a) = 1;
vi b2;
for(int b: get_res(v))
{
if(get_vis(b)) continue;
get_vis(b) = 1;
b2.push_back(b);
// if(b > a) break;
ans.push_back(a+b);
}
for(int b: b2) get_vis(b) = 0;
}
for(int a: get_res(u))
get_visited(a) = 0;
}
if(i == n)
{
sort(ans.begin(), ans.end());
ans.erase(unique(ans.begin(), ans.end()), ans.end());
}
// for(int a: ans) cerr << "a = " << a << '\n';
get_res(i) = ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
// assert(n <= 8'5000'0000);
if(n == 1)
{
cout << "1\n 0\n";
return 0;
}
for(int i = 2; i < n && i*i <= n; i++)
{
// cerr << i << " " << n%i << ' ' << int(n%i == 0) << '\n';
if(n % i == 0)
{
sf.push_back(i);
sf.push_back(n/i);
}
if(i % 1000 == 0)
cerr << "i = " << i << '\n';
}
sf.push_back(n);
sort(sf.begin(), sf.end());
sf.erase(unique(sf.begin(), sf.end()), sf.end());
for(int a: sf)
for(int b: sf)
if(a < b && b%a==0)
get_factors(b).push_back(a);
solve(n);
vi ans = res2[1];
cout << sz(ans) << '\n';
for(int r: ans) cout << r << ' ';
cout << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 ms |
4940 KB |
Output is correct |
3 |
Correct |
4 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
4 ms |
5008 KB |
Output is correct |
6 |
Correct |
5 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Incorrect |
4 ms |
5016 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 ms |
4940 KB |
Output is correct |
3 |
Correct |
4 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
4 ms |
5008 KB |
Output is correct |
6 |
Correct |
5 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Incorrect |
4 ms |
5016 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 ms |
4940 KB |
Output is correct |
3 |
Correct |
4 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
4 ms |
5008 KB |
Output is correct |
6 |
Correct |
5 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Incorrect |
4 ms |
5016 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 ms |
4940 KB |
Output is correct |
3 |
Correct |
4 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
4 ms |
5008 KB |
Output is correct |
6 |
Correct |
5 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Incorrect |
4 ms |
5016 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 ms |
4940 KB |
Output is correct |
3 |
Correct |
4 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
4 ms |
5008 KB |
Output is correct |
6 |
Correct |
5 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Incorrect |
4 ms |
5016 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |