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>
using namespace std;
set<pair<int, int>> vis;
void backtrack(int n, int sum){
if(vis.find({n, sum}) != vis.end())
return;
vis.insert({n, sum});
bool isprime = (n != 1);
for(int k = 2; k <= sqrt(n); k ++)
if(n % k == 0)
backtrack(n / k, sum + k - 1),
backtrack(k, sum + (n/k) - 1),
isprime = false;
if(isprime)
backtrack(1, sum + n - 1);
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
backtrack(n, 0);
set<int> unique;
for(auto &[num, sum] : vis)
if(num == 1)
unique.insert(sum);
cout << unique.size() << '\n';
for(int it : unique)
cout << it << ' ';
}
Compilation message (stderr)
toy.cpp: In function 'int main()':
toy.cpp:28:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
28 | for(auto &[num, sum] : vis)
| ^
# | 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... |