Cod sursa(job #1710011)

Utilizator UPT_sThorUPT sThor UPT_sThor Data 28 mai 2016 14:46:05
Problema Consecutive Scor 0
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 1.36 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <cmath>
#include <algorithm>

#define NMAX 1000005

using namespace std;

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

int T , n ;
pair < int , int > v[NMAX];
int frecv[NMAX];

int main ( void )
{
	int i,j;
	in >> T;
	for ( i = 1 ; i <= T ; ++i ){
	 
         in >> n ;
	memset ( frecv , 0 , sizeof(frecv));
	int contor = 0 ; 
	if ( n % 2 == 1 )
		{
		++frecv[2] ;
		++contor;
		v[contor].first = n/2;
		v[contor].second = n/2 + 1 ;
	}

	for ( j = 3 ; j <= 2*(int) sqrtl(n) ; ++j ) {
        	if ( ( j %2  == 1 && n % j == 0 ) && frecv[j] == 0 ){
                     int a = ( 2 * n / j + 1 - j ) / 2 ;
		     	if ( a > 0 ){
		     ++frecv[j] ;
                     ++contor;
                     v[contor].first = a ;
		     v[contor].second = a + j - 1 ;
 			}
                  }
	else if  ( ( j % 2 == 0  && n %(j/2) == 0)  && frecv[j] == 0 ) {
		
		int a = ( 2 * n / j + 1 - j ) / 2 ;
		if( ( a + ( a+j-1) ) *j ==  2 * n ) {
     	               if ( a > 0 ){
		     ++frecv[j] ;
                     ++contor;
                     v[contor].first = a ;
		     v[contor].second = a + j - 1 ;
 			}
                 }
                
	}
   }
	out << contor << "\n"; 
	for ( j = 1; j <= contor ; ++j )
		out << v[j].first << " " << v[j].second << "\n";
			
	}	
	return 0 ;
}