Cod sursa(job #1935505)

Utilizator cristina_borzaCristina Borza cristina_borza Data 22 martie 2017 14:30:17
Problema Consecutive Scor 0
Compilator cpp Status done
Runda Arhiva ICPC Marime 0.77 kb
#include <fstream>
#include <vector>

#define DIM 150000

using namespace std;

ifstream f ("consecutive.in");
ofstream g ("consecutive.out");

long long n, T, nr;
pair <int, int> sol[DIM];

void solve () {
    f >> n;
    nr = 0;

    for (int a = 2; a * a <= 2 * n; ++a) {
        long long x = (2 * n / a + a - 1) / 2;
        long long y = x - a;

        if (x < 1 || y < 0) {
            continue;
        }

        if (x * (x + 1) - y * (y + 1) == 2 * n) {
            sol[++nr] = make_pair ((int)y + 1, (int)x);
        }
    }

    g << nr << '\n';
    for (int i = 1; i <= nr; ++i) {
        g << sol[i].first << " " << sol[i].second << '\n';
    }
}

int main() {
    f >> T;
    while (T--) {
        solve ();
    }
    return 0;
}