# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
130030 | OptxPrime | Toys (CEOI18_toy) | C++11 | 211 ms | 262144 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 <cmath>
#include<vector>
#include <algorithm>
#include <utility>
#include<stack>
#include<queue>
#include<map>
#include <fstream>
#include<set>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
//map<int,bool> res;
map<int, set<int>> sums;
int maxn=100000;
set<int> fac[10000010];
void num( int x )
{
sums[x].insert( x-1 );
if( x>maxn ){ ///pravo velik broj, kakvih ima najvise stotinjak
for( int i=2;i<=sqrt(x);i++ ){
if( ( x%i )!= 0 ) continue;
if( sums[i].size() == 0 )num(i);
if( sums[ x/i ].size() == 0 ) num( (x/i) );
for( auto j:sums[i] ){
for( auto k:sums[x/i] ){
sums[x].insert( j+k );
}
}
}
}
else{
for( auto i:fac[x] ){
// cout <<x << " " << i << " et " <<endl;
if( i>sqrt(x) ) break;
if( sums[i].size() == 0 ) num(i);
if( sums[x/i].size() == 0 ) num(x/i);
for( auto j:sums[ i ] ){
for( auto k:sums[x/i] ){
// cout << x << " " << i << " " << j << " " << k <<endl;
sums[x].insert( j+k );
}
}
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
for( int i=2;i<=maxn;i++ ){
for( int j=i;j<=maxn;j+=i ){
// cout << j <<endl;
fac[j].insert( i );
}
}
// cout << " bral;e " <<endl;
num(n);
/// brza faktorizacija? jer za svaki broj mi idemo do korjena pa cak i za 10^9 samo su nam bitni do korjena
cout<<sums[n].size()<<endl;
for( auto i:sums[n] )
cout<<i<<" ";
cout<<endl;
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... |