# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
95146 | Retro3014 | Toys (CEOI18_toy) | C++17 | 2802 ms | 17140 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>
using namespace std;
#define INF 1000000001
typedef long long ll;
int N;
vector<int> d;
vector<int> ans;
int multi(int a, int b){
ll x = 1;
while(b--){
x*=(ll)a;
x = min(x, (ll)INF);
}
return min(x, (ll)INF);
}
int answer;
int now;
void dfs(int x, int y){
if(x==31){
if(now==1){
ans.push_back(answer);
}
return;
}
for(int i=y; i<d.size(); i++){
if(multi(d[i], 31-x)>now) return;
if(now%d[i]!=0) continue;
now/=d[i];
answer+=d[i]-1;
dfs(x+1, i);
answer-=d[i]-1;
now*=d[i];
}
}
int main(){
scanf("%d", &N);
for(int i=1; i*i<=N; i++){
if(N%i==0){
d.push_back(i);
if(i*i!=N) d.push_back(N/i);
}
}
sort(d.begin(), d.end());
now = N;
dfs(1, 0);
sort(ans.begin(), ans.end());
for(int i=ans.size()-1; i>0; i--){
if(ans[i]==ans[i-1]) ans[i] = INF;
}
sort(ans.begin(), ans.end());
while(!ans.empty() && ans.back()==INF) ans.pop_back();
printf("%d\n", ans.size());
for(int i=0; i<ans.size(); i++){
printf("%d ", ans[i]);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |