Cod sursa(job #1709112)

Utilizator UTCN_FrunzaUTCN Lazar Nitu Petruta UTCN_Frunza Data 28 mai 2016 10:56:49
Problema Consecutive Scor 100
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.96 kb
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

using namespace std;

long long tests, n, limit, start;
vector< pair<long long, long long> > results;

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

    scanf("%lld", &tests);

    for (int test = 0; test < tests; ++test) {
        scanf("%lld", &n);

        limit = (sqrt(1 + 8 * n) - 1) / 2;
        results.clear();
        for (long long step = 1; step < limit; ++step) {
            if ((2 * n - step * (step + 1)) % (2 * (step + 1)) == 0) {
                results.pb(mp(step, (2 * n - step * (step + 1)) / (2 * (step + 1))));
            }
        }

        printf("%d\n", results.size());
        for (int it = 0; it < results.size(); ++it) {
            printf("%lld %lld\n", results[it].second, results[it].second + results[it].first);
        }
    }

    fclose(stdin);
    fclose(stdout);
    return 0;
}