Cod sursa(job #1709169)

Utilizator UAIC_oricareUAIC oricare UAIC_oricare Data 28 mai 2016 11:08:42
Problema Consecutive Scor 0
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.72 kb

#include <iostream>
#include <fstream>

using namespace std;
int main()
{
    ifstream f ("consecutive.in");
    ofstream g ("consecutive.out");
    typedef struct{int x,y;}NOD;
    NOD v[100000];
    int t,i,n,x,y,j;
    f>>t;
    for(i=1;i<=t;i++)
    {
        f>>n;
        x=n/2+1;y=n/2;j=0;
        while(y>=1)
        {
            int a=(x*(x+1)/2);
            int b=(y*(y-1)/2);
            if(a-b==n)
                {v[++j].x=x;v[j].y=y;x--;y--;}
            else if(a-b<n)
                     y--;
                 else x--;
        }
        g<<j<<'\n';
        for(int k=1;k<=j;k++)
            g<<v[k].y<<' '<<v[k].x<<'\n';
    }

    f.close();
    g.close();
    return 0;
}