Cod sursa(job #2054107)

Utilizator Seb16Ungureanu Paul Sebastian Seb16 Data 1 noiembrie 2017 18:35:32
Problema Consecutive Scor 0
Compilator cpp Status done
Runda Arhiva ICPC Marime 0.71 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <math.h>

using namespace std;

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

int n, t;
long long doubleN;
vector <pair <long long, long long> > v;

int main() {
	fin >> t;
	for (int i = 0; i < t; ++i) {
		fin >> n;
		doubleN = n * 2;
		for (long long j = 1; j <= (n / 2) + 1; ++j) {
			long long delta = 1 + 4 * (doubleN + j * (j - 1));
			long long sqrtDelta = sqrt(delta);
			if (sqrtDelta * sqrtDelta != delta)
				continue;
			long long x2 = (-1 + sqrtDelta) / 2;
			v.push_back(make_pair(j, x2));
		}
	}
	fout << v.size() << '\n';
	for (int i = 0; i < v.size(); ++i) {
		fout << v[i].first << ' ' << v[i].second << '\n';
	}
	return 0;
}