# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
944243 | phoenix0423 | Toys (CEOI18_toy) | C++17 | 994 ms | 6068 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<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#pragma GCC optimize("Ofast")
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define int long long
const int maxn = 2e5 + 5;
vector<int> factorize(int n){
vector<int> p;
for(int i = 1; i <= sqrt(n); i++){
if(n % i == 0){
if(i != 1) p.pb(i);
if(i != n / i) p.pb(n / i);
}
}
sort(p.begin(), p.end());
return p;
}
signed main(void){
fastio;
int n;
cin>>n;
vector<int> p = factorize(n);
vector<vector<int>> mp;
for(auto x : p) mp.pb(factorize(x));
set<int> ans;
auto dfs = [&](auto dfs, int cur, int lst, int cnt) -> void{
if(cur == n){
ans.insert(cnt);
return;
}
auto id = lower_bound(p.begin(), p.end(), n / cur) - p.begin();
int st = lower_bound(mp[id].begin(), mp[id].end(), lst) - mp[id].begin();
for(int i = st; i < mp[id].size(); i++){
dfs(dfs, cur * mp[id][i], mp[id][i], cnt + mp[id][i] - 1);
}
};
dfs(dfs, 1, 1, 0);
cout<<ans.size()<<"\n";
for(auto x : ans) cout<<x<<" ";
cout<<"\n";
}
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... |