Cod sursa(job #1709373)

Utilizator UPB_Hulea_Ionescu_RomanNo Idea UPB_Hulea_Ionescu_Roman Data 28 mai 2016 12:00:16
Problema Consecutive Scor 0
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.74 kb
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <utility>

using namespace std;

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

	vector< pair<int, int> > pairs;

	int t;
	scanf("%i", &t);
	for (int i = 0; i < t; i++) {
		unsigned int n;
		scanf("%ui", &n);
		int k = sqrt(2LL * n);
		for (int j = 2; j <= k; j++) {
			int diff = n - (j - 1) * j / 2;
			int rest = diff % j;
			if (rest == 0) {
				pairs.push_back(make_pair(diff / j, diff / j + j - 1));
			}
		}
		printf("%i\n", pairs.size());
		for (int j = 0; j < pairs.size(); j++) {
			printf("%i %i\n", pairs[j].first, pairs[j].second);
		}
	}


	fclose(stdin);
	fclose(stdout);
}