Cod sursa(job #1709441)

Utilizator UAICHePoBaMaHePoBaMa UAICHePoBaMa Data 28 mai 2016 12:16:27
Problema Consecutive Scor 0
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 1.08 kb
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class s {
public:
	int start, end;
};

bool comp(s s1, s s2)
{
	return s1.end - s1.start < s2.end - s2.start;
}
int main()
{
	ifstream fin("consecutive.in");
	ofstream fout("consecutive.out");
	long long n, x,i;
	s S;
	vector<s> v;
	fin >> n;
	for (i = 0; i < n; i++)
	{
		fin >> x;
		/*int a =1, b = (-1+sqrt(1+8*x))/2;
		int suma = (b * (b + 1)) / 2;
		while (b <= (x+1) / 2)
		{
			if ((2 * x) % (a + b) != 0 && (a+b) * (b-a+1) != 2*x)
			{
				a++;
			}
			else
			{
				S.start = a;
				S.end = b;
				v.push_back(S);
				suma = suma - a;
				a++;
				b++;
			}
		}*/

		long long maxLength = floor(sqrt(2 * x));
		for (int i = 2; i <= maxLength; ++i) {
			if ((x - (i * (i - 1) / 2)) % i == 0) {
				S.start = (x - (i * (i - 1) / 2)) / i;
				S.end = S.start + i - 1;
				v.push_back(S);
			}
		}
		fout << v.size() << endl;
		for (int i = 0; i < v.size(); i++)
		{
			fout << v[i].start << " " << v[i].end << endl;
		}
		v.clear();
	}
	
}