Cod sursa(job #1709160)

Utilizator liisLIIS-Horia-Vlad-Denis liis Data 28 mai 2016 11:07:25
Problema Consecutive Scor 100
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.94 kb
#include <fstream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;
ifstream fin("consecutive.in");
ofstream fout("consecutive.out");
struct str{int inc, sf;} aux;
long long t, n, inc, sf, sum;
vector<str> v;

bool test(str a, str b)
{
    return a.sf - a.inc < b.sf - b.inc;
}

int main()
{
    fin >> t;
    while(t --)
    {
        fin >> n;
        v.clear();
        long long y=2;
        while (y*y<=n*2+5)
        {
            if ((2*n+y-y*y)%(2*y)==0 && (2*n+y-y*y)/(2*y)>0)
            {
                aux.inc = (2*n+y-y*y)/(2*y);
                aux.sf = (2*n+y-y*y)/(2*y)+y-1;
                v.push_back(aux);
            }
            y++;
        }
        sort(v.begin(), v.end(), test);

        fout << v.size() << '\n';
        for(int i = 0; i < v.size(); i ++)
        {
            fout << v[i].inc << ' ' << v[i].sf << '\n';
        }
    }
    return 0;
}