Cod sursa(job #1708952)

Utilizator SegFaultTigersUPB-Necula Nitu Muntean SegFaultTigers Data 28 mai 2016 10:20:52
Problema Consecutive Scor 100
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 1.13 kb
#include<fstream>
#include<vector>
#include<algorithm>

using namespace std;

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

long long t,a,i;
long long n,d;
vector<pair<long long,long long> >sol;

bool cmp(pair<long long,long long>a, pair<long long,long long>b)
{
    return (a.second - a.first) < (b.second-b.first);
}

int main()
{
    f >> t;
    for(; t; --t)
    {
        f >> n;
        n *= 2;
        for(d = 2; d * d <= n; ++d)
            if(n % d == 0)
            {
                a = (n / d) - d + 1;

                if(a % 2 == 0 && a > 0)
                {
                    a /= 2;

                    sol.push_back(make_pair(a, a + d - 1));
                }

                int k = n / d;
                a = (n / k) - k + 1;

                if(a % 2 || a <= 0)
                    continue;

                a /= 2;

                sol.push_back(make_pair(a, a + k - 1));


            }

        g << sol.size() << '\n';

        sort(sol.begin(), sol.end(), cmp);

        for(i = 0; i < sol.size(); ++i)
            g << sol[i].first << ' ' << sol[i].second << '\n';

        sol.clear();
    }

    return 0;
}