Cod sursa(job #2403273)

Utilizator CojocariuAlexandruCojocariu Alexandru CojocariuAlexandru Data 11 aprilie 2019 13:30:30
Problema Consecutive Scor 0
Compilator cpp-64 Status done
Runda Arhiva ICPC Marime 1.23 kb
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <fstream>
#define NMAX 4300000000
#define NMAXS 300000

using namespace std;

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

struct intervale {
	int x, y;
};
intervale I[NMAXS];

int criteriu(intervale a, intervale b) {
	int val1 = a.x - a.y;
	int val2 = b.x - b.y;
	if (val1 < 0)
		val1 = -val1;
	if (val2 < 0)
		val2 = -val2;
	if (val1 < val2)
		return 1;
	else if (val1 == val2) {
		if (a.x < b.x)
			return 1;
		else if (a.x == b.x)
			if (a.y < b.y)
				return 1;
		}
	return 0;
}

int teste;
int i, n, j, p1, p2, k1, k2, ct;

int main(){
	fin >> teste;
	for (i = 1; i <= teste; ++i) {
		fin >> n;
		n *= 2;
		ct = 0;
		for (j = 1; j*j <= n; ++j) {
			if (n%j == 0) {
				p1 = j;
				p2 = n / j;
				k1 = p1 - 1;
				k2 = (p2 - p1 + 1) / 2;
				if (k1 == 0)
					continue;
				I[ct].x = k2;
				I[ct].y = k2+k1;
				++ct;

				/*k1 = p2 - 1;
				k2 = (p1 - p2 + 1) / 2;
				I[ct].x = k2;
				I[ct].y = k2 + k1;
				++ct;*/
				}
			}
		sort(I, I + ct, criteriu);
		fout << ct << '\n';
		for (j = 0; j < ct; ++j)
			fout << I[j].x << ' ' << I[j].y << '\n';
		}
	return 0;
}