Cod sursa(job #1709368)

Utilizator CornelPanicUPB CornelPanic CornelPanic Data 28 mai 2016 11:58:25
Problema Consecutive Scor 100
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.92 kb
#include <iostream>
#include <stdio.h>
#include <cmath>

#define NMAX 350000

using namespace std;

long long N, k, sn, m, L, i, j, numar, T, x;
long long lungime[NMAX], stanga[NMAX];
long long n;

int main() {
    freopen("consecutive.in", "r", stdin);
    freopen("consecutive.out", "w", stdout);

    scanf("%lld", &T);

    while(T--) {
        k = 0; numar = 0;
        scanf("%lld", &N);

        sn = 2 * sqrt(N);
        for(L = 2; L <= sn; ++ L) {
            n = 2 * N + L * L + L;
            if(n % (2*L) == 0) {
                x = (2*N - (L*L - L)) / (2 * L);
                if(x > 0) {
                    stanga[k++] = x;
                    lungime[k - 1] = L;
                    numar ++;
                }
            }
        }
        printf("%lld\n", 1LL * numar);

        for(i = 0; i < k; ++i) {
            printf("%lld %lld\n", 1LL * stanga[i], 1LL * (stanga[i] + lungime[i] - 1));
        }
    }

    return 0;
}