Cod sursa(job #1710283)

Utilizator RanKBrinduse Alexandru RanK Data 28 mai 2016 19:02:28
Problema Consecutive Scor 0
Compilator cpp Status done
Runda Arhiva ICPC Marime 0.93 kb

// http://www.infoarena.ro/problema/consecutive

#include "problems.h"

#define IN_FILE_NAME "consecutive.in"
#define OUT_FILE_NAME "consecutive.out"

#include <list>

using namespace std;

typedef long long int int64;

void RunConsecutive()
{
	freopen(IN_FILE_NAME, "r", stdin);
	freopen(OUT_FILE_NAME, "w", stdout);

	int t, tests;

	scanf("%d", &tests);
	for (t = 0; t < tests; t++)
	{
		int64 S;
		int i;
		int n, m=1;

		list<pair<int64, int64>> arr;

		scanf("%lld", &S);

		for (i = 2; ; i++)
		{
			int64 top = 2 * S - i*i - i;
			if (top < 0)
				break;
			int64 bot = 2 * i;

			if (top % bot == 0)
			{
				int64 m = top / bot;
				int64 n = m + i;
				m++;

				arr.push_back(pair<int64, int64>(m, n));
			}
		}

		printf("%d\n", arr.size());
		while (!arr.empty())
		{
			pair<int64, int64> p = arr.front();
			arr.pop_front();

			printf("%lld %lld\n", p.first, p.second);
		}
	}
}