Cod sursa(job #1709496)

Utilizator mariastStoichitescu Maria mariast Data 28 mai 2016 12:36:00
Problema Consecutive Scor 0
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.63 kb
#include<fstream>
using namespace std;
ifstream f ("consecutive.in");
ofstream g ("consecutive.out");
long long t,i,nr,x,k,j,a[100000][2],n;
int main()
{
    f>>t;
    for(i=1;i<=t;i++){
        f>>nr;
        k=0;
        x=2;
        while((2*nr-x*(x-1))/(2*x)>=1){
            n=(2*nr-x*(x-1))/(2*x);
            if(x*n+x*(x-1)/2==nr){
            k++;
            a[k][1]=n;
            a[k][2]=n+x-1;
            }
            x++;
        }
        if(k==0) g<<0;
        else{
        g<<k<<'\n';
        for(j=1;j<=k;j++){
            g<<a[j][1]<<" "<<a[j][2]<<'\n';
        }
        }
    }
    return 0;
}