Cod sursa(job #1716131)

Utilizator BossuSmekeruStapanulocu1 BossuSmekeru Data 11 iunie 2016 23:47:58
Problema Consecutive Scor 0
Compilator cpp Status done
Runda Arhiva ICPC Marime 0.78 kb
#include <fstream>
#include <cmath>
using namespace std;
int a[1000], b[1000];

int main()
{
    int t, nr, i, j;
    long long n;
    ifstream cin ("consecutive.in");
    ofstream cout ("consecutive.out");
    cin >> t;

    for (i = 0; i < t; ++i){
        cin >> n;
        nr = 0;

        for (j = 1; (j + 1) * (j + 1) <= 2 * n; ++j){

            if ((2 * n) % (j + 1) == 0){

                if ((2 * n - j * j - j) % (2 * j + 2) == 0){
                    ++nr;
                    a[nr] = (2 * n - j * j - j) / (2 * j + 2);
                    b[nr] = a[nr] + j;
                }

            }
        }

        cout << nr << "\n";

        for (j = 1; j <= nr; ++j){
            cout << a[j] << " " << b[j] << "\n";
        }

    }

    return 0;
}