Cod sursa(job #2241202)

Utilizator vladm98Munteanu Vlad vladm98 Data 15 septembrie 2018 12:06:07
Problema Consecutive Scor 100
Compilator cpp Status done
Runda Arhiva ICPC Marime 0.87 kb
#include <iostream>
#include <algorithm>
#include <fstream>

using namespace std;

long long a[100001];
long long b[100001];

int main()
{
    ifstream fin ("consecutive.in");
    ofstream fout ("consecutive.out");
    int t, contor;
    fin >> t;
    for (int i = 1; i <= t; ++i) {
        long long suma;
        contor = 0;
        fin >> suma;
        for (long long x = 2; x * x <= 2 * suma; ++x) {
            long long result = 2 * suma - x * x + x;
            if (result % (2 * x) == 0) {
                result /= (2 * x);
                if (result > 0) {
                    contor += 1;
                    a[contor] = result;
                    b[contor] = (result + x - 1);
                }
            }
        }
        fout << contor << '\n';
        for (int i = 1; i <= contor; ++i) {
            fout << a[i] << ' ' << b[i] << '\n';
        }
    }
    return 0;
}