Cod sursa(job #1709631)

Utilizator TeamFIIDUAIC backtrackers TeamFIID Data 28 mai 2016 13:08:27
Problema Consecutive Scor 0
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.82 kb
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
long long int n;
int T;
vector <pair <int, int> > sol;
int main()
{
	freopen("consecutive.in", "r", stdin);
	freopen("consecutive.out", "w", stdout);
	cin >> T;
	long long int x;
	while (T)
	{
		T--;
		//int nr = 0;
		cin >> n;
		long long lim_x;
		lim_x = (sqrt(long double(1LL + 8LL * n)) - 1) / 2;
		for (x = 2; x <= lim_x; x++)
		{
			int offset = (x * (x - 1) / 2) / x;
			if (n % x == ((x *(x - 1) / 2) % x) )
			{
				//am caz bun;
				int a = n / x - offset;
				int b = a + x - 1;
				sol.push_back(make_pair(a, b));
			}
		}
		cout << sol.size() << '\n';
		for (int i = 0; i < sol.size(); i++)
			cout << sol[i].first <<' '<< sol[i].second << '\n';
		sol.clear();
	}
	return 0;
}