Pagini recente » Cod sursa (job #3173217) | Cod sursa (job #2518521) | Cod sursa (job #577913) | Cod sursa (job #3210596) | Cod sursa (job #1709188)
#include <iostream>
#include <stdlib.h>
#include <cstdio>
#include <fstream>
#include <vector>
using namespace std;
vector<pair<int,int>> findSummations(int n) {
bool hasSol = true;
int numerator;
int i = 2;
vector<pair<int, int>> solutions;
solutions.reserve((int) sqrt(n));
while (hasSol) {
hasSol = false;
if (i * (i + 1) <= 2 * n) {
hasSol = true;
numerator = n - i * (i - 1) / 2;
if (numerator % i == 0) {
int k = numerator / i;
solutions.push_back(make_pair(k, k + i - 1));
}
}
i++;
}
return solutions;
}
int main()
{
ios::sync_with_stdio(false);
ifstream inFile("consecutive.in");
ofstream outFile("consecutive.out");
int T;
inFile >> T;
int n;
for (int t = 0; t < T; t++) {
inFile >> n;
vector<pair<int,int>> solutions = findSummations(n);
int size = solutions.size();
outFile << size << endl;
for (int i = 0; i < size; i++) {
outFile << solutions[i].first << " " << solutions[i].second << endl;
}
}
inFile.close();
outFile.close();
return 0;
}