Submission #826102

#TimeUsernameProblemLanguageResultExecution timeMemory
826102farukToys (CEOI18_toy)C++17
59 / 100
5038 ms5120 KiB
#include <bits/stdc++.h> #define mp make_pair #define all(a) a.begin(), a.end() using namespace std; typedef long long ll; typedef pair<int, int> pii; const int maxn = 1e6 + 2; /*vector<int> min_prim(maxn); vector<vector<int> > facs(maxn); void sito() { for (ll i = 1; i < maxn; i++) { for (ll j = i; j < maxn; j += i) facs[j].push_back(i); } } */ vector<int> min_prim(maxn); void sito() { for (ll i = 2; i < maxn; i++) { if (min_prim[i] != 0) continue; for (ll j = i ; j < maxn; j += i) if (min_prim[j] == 0) min_prim[j] = i; } } vector<int> facs; void get_small_primes(int a) { if (a == 1) return; facs.push_back(min_prim[a]); get_small_primes(a / min_prim[a]); } vector<int> get_small_factors(int a) { facs = vector<int>(); get_small_primes(a); vector<int> factors; factors.push_back(1); vector<int> temp; facs.push_back(1e9); int cnt = 0; for (int i = 0; i < facs.size() - 1; i++) { cnt++; if (facs[i] != facs[i + 1]) { int val = 1; for (int j = 0; j < cnt; j++) { val *= facs[i]; for (int a : factors) temp.push_back(a * val); } factors.insert(factors.end(), all(temp)); temp.clear(); cnt = 0; } } sort(all(factors)); return factors; } vector<int> factors; vector<int> get_big_factors(int a, int l) { for (int i = 1; i * i <= a and i <= l; i++) { if (i * i == a) factors.push_back(a); else { factors.push_back(i); if (a / i <= l) factors.push_back(a/i); } } sort(all(factors)); return factors; } vector<bool> there(maxn); set<int> ans; void recur(int n, int csum, int l) { if (n == 1) { if (csum > maxn) ans.insert(csum); else { if (there[csum]) return; there[csum] = true; } return; } vector<int> factors; if (n < maxn) factors = get_small_factors(n); else factors = get_big_factors(n, l); for (int i = 0; i < factors.size(); i++) { // the actual factor is a and left over is n/a int a = factors.at(i); if (a > l) return; if (a == 1) continue; recur(n/a, csum + a - 1, a); } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); sito(); int n; cin >> n; recur(n, 0, n+1); vector<int> anss; for (int i = 0; i < maxn; i++) if (there[i]) anss.push_back(i); for (int a : ans) anss.push_back(a); cout << anss.size() << "\n"; for (int a : anss) cout << a <<" "; cout <<"\n"; }

Compilation message (stderr)

toy.cpp: In function 'std::vector<int> get_small_factors(int)':
toy.cpp:48:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for (int i = 0; i < facs.size() - 1; i++) {
      |                     ~~^~~~~~~~~~~~~~~~~
toy.cpp: In function 'void recur(int, int, int)':
toy.cpp:101:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |     for (int i = 0; i < factors.size(); i++) { // the actual factor is a and left over is n/a
      |                     ~~^~~~~~~~~~~~~~~~
#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...