Pagini recente » Cod sursa (job #3039460) | Cod sursa (job #948510) | Cod sursa (job #2745810) | Cod sursa (job #547194) | Cod sursa (job #2403270)
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <fstream>
#define NMAX 4300000000
#define NMAXS 66000
using namespace std;
ifstream fin("consecutive.in");
ofstream fout("consecutive.out");
struct intervale {
int x, y;
};
intervale I[NMAXS];
int criteriu(intervale a, intervale b) {
int val1 = a.x - a.y;
int val2 = b.x - b.y;
if (val1 < 0)
val1 = -val1;
if (val2 < 0)
val2 = -val2;
if (val1 < val2)
return 1;
else if (val1 == val2) {
if (a.x < b.x)
return 1;
else if (a.x == b.x)
if (a.y < b.y)
return 1;
}
return 0;
}
int teste;
int i, n, j, p1, p2, k1, k2, ct;
int main(){
fin >> teste;
for (i = 1; i <= teste; ++i) {
fin >> n;
n *= 2;
ct = 0;
for (j = 1; j*j <= n; ++j) {
if (n%j == 0) {
p1 = j;
p2 = n / j;
k1 = p1 - 1;
k2 = (p2 - p1 + 1) / 2;
if (k1 == 0)
continue;
I[ct].x = k2;
I[ct].y = k2+k1;
++ct;
/*k1 = p2 - 1;
k2 = (p1 - p2 + 1) / 2;
I[ct].x = k2;
I[ct].y = k2 + k1;
++ct;*/
}
}
sort(I, I + ct, criteriu);
fout << ct << '\n';
for (j = 0; j < ct; ++j)
fout << I[j].x << ' ' << I[j].y << '\n';
}
return 0;
}