# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1068461 | cpdreamer | Toys (CEOI18_toy) | C++14 | 5065 ms | 2368 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>
#include <ext/pb_ds/assoc_container.hpp>
#include <utility>
#define V vector
#define F first
#define S second
#define P pair
#define pb push_back
#define all(v) v.begin(),v.end()
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
static int called = 0;const long long MOD = 1e9+7; // 1e9 + 7
void file(){
freopen("input.txt.txt","r",stdin);
freopen("output.txt.txt","w",stdout);
}
ll binary_expo(ll a,ll b,ll m){
ll res=1;
while(b){
if(b%2==1){res=(res*a)%m;b--;}
b/=2;
a=(a*a)%m;
}
return res;
}
bool prime(ll p){
for(int i=0;i<100;i++) {
ll b = rand()%p;
if(b!=0) {
ll res = binary_expo(b, p, p);
if (res != b % p)
return false;
}
}
return true;
}
void solve() {
int n;
cin>>n;
if(n==1){
cout<<1<<endl;
cout<<0<<endl;
return;
}
V<int>primes;
V<int>factor;
for(int i=2;i<=n;i++){
if(prime(i))
primes.pb(i);
}
int p=0;
while(n>1){
if(n%primes[p]==0){
n/=primes[p];
factor.pb(primes[p]);
}
else
p++;
}
set<V<int>>st;
st.insert({factor[0]});
for(int i=1;i<factor.size();i++) {
set<V<int>>st1;
for (auto &u: st) {
for (int j=0;j<u.size();j++) {
V<int>v=u;
v[j]*=factor[i];
sort(all(v));
st1.insert(v);
}
V<int>v=u;
v.pb(factor[i]);
sort(all(v));
st1.insert(v);
}
st=st1;
}
V<int>ans;
for(auto u:st) {
int c = 0;
for (auto x: u) {
c += x - 1;
}
ans.pb(c);
}
sort(all(ans));
auto it=unique(all(ans));
ans.resize(distance(ans.begin(),it));
cout<<ans.size()<<endl;
for(auto u:ans)
cout<<u<<" ";
cout<<endl;
}
int main(){
//file();
solve();
}
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... |