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;
const int MAXV = 40;
int n, s[MAXV], marc, sz;
vector<int> v;
set<int> ans;
set<int> :: iterator it;
map<pair<int, pair<int, int> > , bool> mp;
void BKT(int sum, int last, int qtt)
{
if(mp[{sum, {last, qtt}}]) return;
mp[{sum, {last, qtt}}] = true;
if(marc == (1 << sz) - 1)
{
ans.insert(sum + last - qtt);
return;
}
for(int i = 0; i < sz; i++)
{
if(marc & (1 << i)) continue;
marc += (1 << i);
if(qtt) BKT(sum, last * v[i], qtt);
BKT(sum + last, v[i], qtt + 1);
marc -= (1 << i);
}
}
int main ()
{
scanf("%d", &n);
for(long long int i = 2; i * i <= n; i++)
while(n % i == 0)
n /= i, v.push_back(i);
if(n > 1) v.push_back(n);
sz = v.size();
sort(v.begin(), v.end());
BKT(0, 0, 0);
printf("%d\n", (int) ans.size());
for(it = ans.begin(); it != ans.end(); it++) printf("%d ", (*it));
printf("\n");
}
Compilation message (stderr)
toy.cpp: In function 'int main()':
toy.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
35 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
# | 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... |