Pagini recente » Cod sursa (job #719427) | Cod sursa (job #3212625) | Cod sursa (job #66818) | Cod sursa (job #252125) | Cod sursa (job #1709268)
#include<iostream>
#include<fstream>
#include<vector>
#include<math.h>
using namespace std;
ifstream fin("consecutive.in");
ofstream fout("consecutive.out");
int T, N;
int main()
{
fin >> T;
for (int t = 0; t < T; t++) {
fin >> N;
vector<int> sol_low;
vector<int> sol_high;
for (int i = 1; i < N/2 + 1; i++) {
int c = 2 * N + i * i - i;
int aux = 1 + 4 * c;
//cout << i << " " <<aux<<"\n";
int s = round(sqrt(aux));
if (s * s == aux) {
int b = (-1 + s);
if (b % 2 )
continue;
b = b / 2;
//cout << i << " " << aux << " " << b<<"\n";
if (b > i && b <= N/2 + 1) {
sol_high.push_back((-1 + s) / 2);
sol_low.push_back(i);
}
}
}
fout << sol_low.size() << '\n';
for (int i = 0; i < sol_low.size(); i++) {
fout << sol_low[i] << " " << sol_high[i] << '\n';
}
}
}