Submission #73466

#TimeUsernameProblemLanguageResultExecution timeMemory
73466jiaqing23Toys (CEOI18_toy)C++14
79 / 100
5092 ms3696 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pop pop_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;
typedef pair<int,pair<int,int> > tri;

set<ll> ans;
ll n;
vector<ll> fac;
vector<ll> factor_tem, factor;
ll sum = 0;

void factorize(ll n, ll now, ll smallfac){
    if(now == n) ans.insert(sum-fac.size());

    for(int i = smallfac; factor[i] <= n ; i++){
        ll k = factor[i]*now;
        if(k>n) break;
        if(n%k == 0){
            fac.pb(factor[i]);
            sum+=(factor[i]);
            factorize(n, k, i);
            sum-=(factor[i]);
            fac.pop();
        }
    }
}

int main()
{
    scanf("%lld",&n);

    for(int i = 1; i * i <= n; i++){
        if(n%i==0) {
            factor_tem.pb(i);
            if(i*i!=n)factor_tem.pb(n/i);
        }
    }
    int k = factor_tem.size();
    factor.resize(k+5);
    for(int i = 0; i < k/2; i++){
        factor[i] = factor_tem[2*i];
        factor[k-i-1] = factor_tem[2*i+1];
    }
    if(k%2==1) factor[k/2] = factor_tem[k-1];
    factor[k] = (ll)1e10;

    factorize(n, 1, 1);

    printf("%d\n",ans.size());

    for(set<ll>::iterator it = ans.begin(); it!=ans.end(); it++){
        printf("%lld ",*it);
    }
	return 0;
}

Compilation message (stderr)

toy.cpp: In function 'int main()':
toy.cpp:68:29: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::set<long long int>::size_type {aka long unsigned int}' [-Wformat=]
     printf("%d\n",ans.size());
                   ~~~~~~~~~~^
toy.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&n);
     ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...