Cod sursa(job #2054111)

Utilizator KenpachiDonoAndrei Grigoras KenpachiDono Data 1 noiembrie 2017 18:36:48
Problema Consecutive Scor 100
Compilator cpp Status done
Runda Arhiva ICPC Marime 1.03 kb
#include <fstream>
#define NMAX 66000

using namespace std ;

ifstream fin ( "consecutive.in" ) ;
ofstream fout ( "consecutive.out" ) ;

long long int N, nrT, sol ;

struct elem
{
    long long int st ;
    long long int dr ;
} SOL[NMAX];

void solve ( long long int N )
{
    sol = 0 ;
    long long int NN = 2 * N - 1 ;
    for ( long long int i = 2 ; i * i <= NN ; i++ )
    {
        long long int firstElem = 0 ;
        long long int eq = 2 * N ;
        long long int x = i - 1 ;
        if ( ( eq - x * x - x ) % ( 2 * ( x + 1 ) ) == 0 )
        {
            firstElem = ( eq - x * x -x ) / ( 2 * ( x + 1 ) ) ;
            sol++ ;
            SOL[sol].st = firstElem ;
            SOL[sol].dr = firstElem + i - 1 ;
        }
    }
    fout << sol << '\n' ;
    for ( long long int i = 1 ; i <= sol ; i++ )
        fout << SOL[i].st << ' ' << SOL[i].dr << '\n' ;
}

int main()
{
    fin >> nrT ;
    for ( int i = 1 ; i <= nrT ; i++ )
    {
        fin >> N ;
        solve(N) ;
    }
    return 0;
}