Cod sursa(job #1709832)

Utilizator UBB_RETIRED_BUT_DANGEROUSUBBTEAM UBB_RETIRED_BUT_DANGEROUS Data 28 mai 2016 14:04:47
Problema Consecutive Scor 100
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 1.18 kb
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

ifstream in("consecutive.in");
ofstream out("consecutive.out");

bool isPowerOfTwo(long long n)
{
	if ((n & (n - 1)) == 0)
		return 1;
	return 0;
}

bool isPrime(int x)
{
	if (x == 2)
	{
		return true;
	}
	if (x % 2 == 0)
	{
		return false;
	}

	int right = sqrt(x);
	for (int i = 3; i <= right; i += 2)
	{
		if (x % i == 0)
		{
			return false;
		}
	}

	return true;
}

bool cmp(pair<long long, long long> x, pair<long long, long long> y)
{
	if ((y.second - y.first) >= (x.second - x.first))
		return true;
	return false;
}

int main()
{
	int T; in >> T;
	for (int t = 0; t < T; t++)
	{
		long long N;
		in >> N;
		vector<pair<int, int>> sol;

		long long TR = 1, k = 1;
		while (TR<N)
		{
			long long X = N - TR;
			if (X % (k + 1) == 0)
			{
				long long t1 = X / (k + 1);
				sol.push_back(make_pair(t1, t1 + k));
			}
			k++; TR += k;
		}
		sort(sol.begin(), sol.end(), cmp);
		unsigned int size = sol.size();
		out << size << '\n';
		for (int i = 0; i < size; i++)
		{
			out << sol[i].first << ' ' << sol[i].second << '\n';
		}
	}

	return 0;
}