Cod sursa(job #1711862)

Utilizator lucaperjuLuca Perju Verzotti lucaperju Data 1 iunie 2016 13:03:06
Problema Consecutive Scor 100
Compilator cpp Status done
Runda Arhiva ICPC Marime 0.91 kb
#include <fstream>

using namespace std;
ifstream in ("consecutive.in");
ofstream out ("consecutive.out");
int main()
{
    long long n,nr,i,j,cnt,w,s;
    in>>n;
    for(i=1;i<=n;i++)
    {
        in>>nr;
        nr=nr*2;
        cnt=0;
        for(j=2;j*j<=nr;j++)
        {
            if(nr%j==0)
            {
                s=0;
                for(w=nr/2/j-(j-1)/2;w<=nr/2/j-(j-1)/2+j-1;w++)
                {
                    s=s+w;
                }
                if(s==nr/2)
                cnt++;
            }
        }
        out<<cnt<<"\n";
        for(j=2;j*j<=nr;j++)
        {
            if(nr%j==0)
            {
                s=0;
                for(w=nr/2/j-(j-1)/2;w<=nr/2/j-(j-1)/2+j-1;w++)
                {
                    s=s+w;
                }
                if(s==nr/2)
                out<<nr/2/j-(j-1)/2<<" "<<nr/2/j-(j-1)/2+j-1<<"\n";
            }
        }
    }
    return 0;
}