Cod sursa(job #1709043)

Utilizator theboysUVT Talpau Craciun Ciobanu theboys Data 28 mai 2016 10:41:21
Problema Consecutive Scor 100
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.6 kb
#include <stdio.h>
#include <math.h>

struct QQ{
	int a, b;
};

QQ q[100100];
int q_s;

int main(){
	
	freopen("consecutive.in", "r", stdin);
	freopen("consecutive.out", "w", stdout);
	
	long long T, N, k, n2, j;
	
	scanf("%lld", &T);
	
	for(; T > 0; --T){
		scanf("%lld", &N);
		
		n2 = 8*N + 1;
		k = sqrt(n2);
		k /= 2;
		
		j = 1; q_s = 0;
		for(int i = 2; i <= k; j += i, ++i){

			if(((N - j) % i) != 0)
				continue;
			
			q[q_s].a = (N - j) / i;
			q[q_s].b = q[q_s].a + i - 1;
			q_s++;
		}
		
		printf("%d\n", q_s);
		for(int i = 0; i < q_s; ++i){
			printf("%d %d\n", q[i].a, q[i].b);
		}
	}

	
return 0;
}