Submission #267047

#TimeUsernameProblemLanguageResultExecution timeMemory
267047Kenzo_1114Toys (CEOI18_toy)C++17
19 / 100
1 ms384 KiB
#include<bits/stdc++.h>
using namespace std;

int n, s[40];
vector<int> v;
vector<pair<int, int> > ans[40];
set<int> ANS;
set<int> :: iterator it;

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

	int sq = sqrt(n) + 1;
	for(int i = 2; i <= sq; i++)
		while(n % i == 0)	
			n /= i, v.push_back(i);
	if(n > 1)	v.push_back(n);

	v.push_back(0);
	sort(v.begin(), v.end());

	int sz = v.size();
	s[0] = 1;
	for(int i = 1; i < sz; i++)	s[i] = s[i - 1] * v[i];

	ans[0].push_back({0, 0});
	for(int i = 1; i < sz; i++)
		for(int j = 1; j <= i; j++)
			for(int k = 0; k < ans[j - 1].size(); k++)
			{
				int sum = ans[j - 1][k].first;
				int qtt = ans[j - 1][k].second;
				ans[i].push_back(make_pair(sum + s[i] / s[j - 1], qtt + 1));
			}

/*
	for(int i = 0; i < sz; i++)
	{
		printf("\nans[%d] : \n", i);
		for(int j = 0; j < ans[i].size(); j++)	printf("(%d, %d) ", ans[i][j].first, ans[i][j].second);
		printf("\n");
	}
*/

	for(int i = 0; i < ans[sz - 1].size(); i++)	ANS.insert(ans[sz - 1][i].first - ans[sz - 1][i].second);

	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:30:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |    for(int k = 0; k < ans[j - 1].size(); k++)
      |                   ~~^~~~~~~~~~~~~~~~~~~
toy.cpp:46:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |  for(int i = 0; i < ans[sz - 1].size(); i++) ANS.insert(ans[sz - 1][i].first - ans[sz - 1][i].second);
      |                 ~~^~~~~~~~~~~~~~~~~~~~
toy.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 |  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...