Cod sursa(job #1709081)

Utilizator SegfaultTamersUPB SegFaultTamers SegfaultTamers Data 28 mai 2016 10:49:37
Problema Consecutive Scor 0
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.99 kb
#include <iostream>
#include <fstream>
#include <queue>

using namespace std;

int main() {
    ifstream f("consecutive.in");
    ofstream g("consecutive.out");

    int t, n;

    f >> t;
    for (int tst = 0; tst < t; ++tst) {
        queue<pair<int, int> > q;
        f >> n;
        for (int k = 2; ; ++k) {
            int d = n / k;
            if (k % 2 == 1) {
                if (d - k / 2 <= 0) {
                    break;
                }
                if (d % 2 == n % 2) {
                    q.push(make_pair(d - k / 2, d + k / 2));
                }
            } else {
                if (d - k / 2 + 1 <= 0) {
                    break;
                }
                if ((2 * d + 1) * (k / 2) == n) {
                    q.push(make_pair(d - k / 2 + 1, d + k / 2));
                }
            }
        }

        g << q.size() << '\n';
        while (!q.empty()) {
            g << q.front().first << ' ' << q.front().second << '\n';
            q.pop();
        }
    }

    return 0;
}