Cod sursa(job #2347751)

Utilizator GeorgeCalinPetruta George-Calin GeorgeCalin Data 19 februarie 2019 08:22:11
Problema Consecutive Scor 0
Compilator cpp-64 Status done
Runda Arhiva ICPC Marime 0.77 kb
#include <fstream>
#define nmax 100002
using namespace std;
ifstream fin("consecutive.in");
ofstream fout("consecutive.out");

long long sol[nmax],sol1[nmax];
int c=0;
long long x,y;

bool pot(long long n,long long k)
{
    if(n%(k+1)==0&&(n/(k+1)-k)%2==0)
    {
        x=(n/(k+1)-k)/2;
        y=x+k;
        return 1;
    }
    return 0;
}

int main()
{
    long long n;
    int t;
    fin>>t;
    for(int i=1;i<=t;i++)
    {
        c=0;
        fin>>n;
        for(int j=1;j*j<=2*n;j++)
            if(pot(2*n,j)&&x)
            {
                sol[++c]=((2*n)/(j+1)-j)/2;
                sol1[c]=sol[c]+j;
            }
        fout<<c<<"\n";
        for(int j=1;j<=c;j++)
            fout<<sol[j]<<" "<<sol1[j]<<"\n";
    }
    return 0;
}