Cod sursa(job #1708938)

Utilizator UAIC_The_RobotsUAIC-Tucar-Onesim-Vintur UAIC_The_Robots Data 28 mai 2016 10:18:30
Problema Consecutive Scor 100
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 1.02 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
#define Vmax 100000
using ll = long long;
using pii = pair<int,int>;

vector< pii > sol;

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

    int i, t;
    ll d, n, x;

    for(cin >> t; t; --t)
    {
        cin >> n;

        sol.clear();

        for(d = 2; d * d < 2 * n; ++d)
            if((2 * n) % d == 0 && (2 * n - d * (d - 1)) % (2 * d) == 0)
        {
            x = (2 * n - d * (d - 1)) / (2 * d);

            if(x > 0) sol.emplace_back(x, x + d - 1);
        }

        cout << sol.size() << '\n';
        for(auto &s : sol) cout << s.first << ' ' << s.second << '\n';
    }

    return 0;
}

/*
void Sieve(int n)
{
    int i, j;

    primes.push_back(2);
    for(i = 3; i < n; i += 2)
        if(isPrime[i])
    {
        primes.push_back(i);

        if(i <= 1000)
            for(j = i * i; j < Vmax; j += i + i) isPrime[j] = false;
    }
}*/