Cod sursa(job #1709166)

Utilizator UTCN_heapstrUTCN HeapStr UTCN_heapstr Data 28 mai 2016 11:08:31
Problema Consecutive Scor 100
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.97 kb
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <string.h>
#include <math.h>

using namespace std;
vector<pair<int, int>> sol;

void solve(int n){
	sol.clear();

	for (long long x = 2; x <= 4 * sqrt(n); x++){
		long long num = 2LL * n - x*x - x;
		long long denom = 2LL * x;

		if (num % denom == 0){
			long long i = num / denom;

			int first = (int)(i+1);
			int last = (int)(i + x);

			if (first >= 1 && first <= n && last >= 1 && last <= n){
				sol.push_back(make_pair(first, last));
			}
		}
	}

	printf("%d\n", sol.size());

	for (int i = 0; i < sol.size(); i++){
		printf("%d %d\n", sol[i].first, sol[i].second);
	}
}

int main(){
	freopen("consecutive.in", "r", stdin);
	freopen("consecutive.out", "w", stdout);

	int t, n;

	scanf("%d", &t);

	for (int i = 0; i < t; i++){
		scanf("%d", &n);

		solve(n);
	}

	return 0; 
}