Cod sursa(job #1985421)

Utilizator emyll96Constantinescu Emil emyll96 Data 27 mai 2017 21:11:16
Problema Consecutive Scor 0
Compilator cpp Status done
Runda Arhiva ICPC Marime 0.9 kb
#include<stdio.h>
#include<math.h>
#include<vector>
using namespace std;
long long unsigned i, teste, nr, k,cate,j,aux;
vector<long long unsigned>alfa;
int main()
{
	FILE*A, *B;
	A = fopen("consecutive.in", "r");
	B = fopen("consecutive.out", "w");
	fscanf(A, "%llu", &teste);
	
	
	for (i = 1; i <= teste; i++)
	{
		cate = 0;
		alfa.clear();
		fscanf(A, "%llu", &nr);
		for (j = 1; j <= nr / 2; j++)
		{
			k = nr;
			aux = (2*j-1)*(2*j-1) + 8 * k;
			if (floor(sqrt(float(aux)))*floor(sqrt(float(aux))) == aux)
			{
				aux = floor(sqrt(float(aux)));
				if (aux % 2 == 1&&aux>=1)
				{
					cate++;
					aux = (1-2*j + aux) / 2;
					alfa.push_back(j);
					alfa.push_back(aux-1+j);
				}
			}
			
			
		}
		fprintf(B, "%llu\n", cate);
		for (int o = alfa.size()-1; o >= 1; o-=2)
			{
				fprintf(B, "%llu %llu\n", alfa.at(o - 1), alfa.at(o));
			}

	}
	fclose(A);
	fclose(B);
}