Cod sursa(job #1716108)

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

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; (2 * n - j * j - j) >= (2 * j + 2); j++){
            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;
}