Cod sursa(job #1708982)

Utilizator UTCN_TBDUTCN Furdui Moldovan Militaru UTCN_TBD Data 28 mai 2016 10:26:47
Problema Consecutive Scor 0
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.67 kb
#include <fstream>
#include <vector>
using namespace std;

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

vector<pair<int, int> > numbers;

int main()
{
	int t;
	long long n, l, a, aux;
	fin >> t;
	bool ok;
	for (int tt = 0; tt < t; tt++) {
		fin >> n;
		for (l = 2;; l++) {
			aux = n - l * (l + 1) / 2;
			if (aux < 0) {
				break;
			}
			if (aux % l == 0) {
				a = aux / l;
				numbers.push_back(make_pair(a + 1, a + l));
			}
		}
		fout << numbers.size() << '\n';
		for (int i = 0; i < numbers.size(); i++) {
			fout << numbers[i].first << ' ' << numbers[i].second << '\n';
		}
	}
	fin.close();
	fout.close();
	return 0;
}