Cod sursa(job #1806856)

Utilizator tanasaradutanasaradu tanasaradu Data 15 noiembrie 2016 18:59:58
Problema Consecutive Scor 100
Compilator cpp Status done
Runda Arhiva ICPC Marime 1.02 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("consecutive.in");
ofstream fout("consecutive.out");
int a[5005],cnt;
 long long n;
void Descompunere()
{
    long long i;
    cnt=0;
    a[++cnt]=n;
    for(i=2;1LL*i*i<n;i++)
        if(n%i==0)
    {
        a[++cnt]=i;
        a[++cnt]=n/i;
    }
    if(i*i==n)
        a[++cnt]=i;
    sort(a+1,a+cnt+1);
}
void Rezolvare()
{
    int i,j,sol=0;
    long long x;
    unsigned long long x1;
    for(i=1;i<=cnt;i++)
    {
        x=n/a[i];
        x=x+1-a[i];
        if(x%2==0 and (x/2)>0)
            sol++;
    }
    fout<<sol<<"\n";
    for(i=1;i<=cnt;i++)
    {
        x=n/a[i];
        x=x+1-a[i];
        if(x%2==0 and (x/2)>0)
        {
            x=x/2;
            x1=(x+a[i]-1);
            fout<<x<<" "<<x1<<"\n";
        }
    }
}
int main()
{
    int i,teste;
    fin>>teste;
    for(i=1;i<=teste;i++)
    {
        fin>>n;
        n=n*2;
        Descompunere();
        Rezolvare();
    }
    return 0;
}