Submission #267082

#TimeUsernameProblemLanguageResultExecution timeMemory
267082peuchToys (CEOI18_toy)C++17
39 / 100
5054 ms812 KiB
#include<bits/stdc++.h> using namespace std; const int MAXN = 2e4; int n; int cnt; int v[MAXN], qnt[MAXN]; set<int> divisor; set<int> ans; void getDiv(int num); void bt(int cur, int val, int num); void calcDP(int num); int main(){ scanf("%d", &n); calcDP(n); printf("%lu\n", ans.size()); set<int> :: iterator it; for(it = ans.begin(); it != ans.end(); it++){ printf("%d ", *it); } printf("\n"); } void getDiv(int num){ memset(v, 0, sizeof(v)); memset(qnt, 0, sizeof(qnt)); divisor.clear(); cnt = 0; int x = num; for(int i = 2; i * i <= n; i++){ if(x % i == 0){ v[++cnt] = i; while(x % i == 0) qnt[cnt]++, x /= i; } } bt(1, 1, num); } void calcDP(int num){ getDiv(num); set<int> aux = divisor; set<int> ret; set<int> :: iterator it, it1, it2; set<int> aux1, aux2; for(it = aux.begin(); it != aux.end(); it++){ calcDP(*it); aux1 = ans; calcDP(num / *it); aux2 = ans; for(it1 = aux1.begin(); it1 != aux1.end(); it1++) for(it2 = aux2.begin(); it2 != aux2.end(); it2++) ret.insert(*it1 + *it2); } ans = ret; ans.insert(num - 1); } void bt(int cur, int val, int num){ if(cur > cnt){ if(val == 1 || val == num) return; divisor.insert(min(val, num / val)); return; } int aux = 1; for(int i = 0; i <= qnt[cur]; i++){ bt(cur + 1, val * aux, num); aux *= v[cur]; } }

Compilation message (stderr)

toy.cpp: In function 'int main()':
toy.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |  scanf("%d", &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...