Submission #161349

#TimeUsernameProblemLanguageResultExecution timeMemory
161349luciocfToys (CEOI18_toy)C++14
59 / 100
5037 ms1080 KiB
#include <bits/stdc++.h>

using namespace std;

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

	if (n == 1)
	{
		printf("1\n0\n");
		return 0;
	}

	vector<int> p;

	int aux = n;

	for (int i = 2; i*i <= aux; i++)
	{
		while (aux%i == 0)
		{
			aux /= i;
			p.push_back(i);
		}
	}

	if (aux > 1) p.push_back(aux);

	set<int> ans;

	do
	{
		for (int mask = 0; mask < (1<<((int)p.size()-1)); mask++)
		{
			if (ans.size() >= 27000)
			{
				printf("%d\n", ans.size());
				for (auto x: ans)
					printf("%d ", x);
				printf("\n");
				return 0;
			}

			int soma = 0;
			int prod = 1, prod2 = 1;

			for (int i = 0; i < ((int)p.size()-1); i++)
			{
				prod *= p[i];

				if (mask&(1<<i))
				{
					soma += (prod-1);
					prod2 *= prod;
					prod = 1;
				}
			}

			prod *= p.back();
			soma += (prod-1);
			prod2 *= prod;

			if (prod2 == n)
				ans.insert(soma);
		}
	} while (next_permutation(p.begin(), p.end()));

	printf("%d\n", ans.size());
	for (auto x: ans)
		printf("%d ", x);
	printf("\n");
}

Compilation message (stderr)

toy.cpp: In function 'int main()':
toy.cpp:39:30: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::set<int>::size_type {aka long unsigned int}' [-Wformat=]
     printf("%d\n", ans.size());
                    ~~~~~~~~~~^
toy.cpp:70:27: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::set<int>::size_type {aka long unsigned int}' [-Wformat=]
  printf("%d\n", ans.size());
                 ~~~~~~~~~~^
toy.cpp:8:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  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...