Cod sursa(job #1709381)

Utilizator stud.ubbstud ubb stud.ubb Data 28 mai 2016 12:02:15
Problema Consecutive Scor 0
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.7 kb
#include <iostream>
#include <queue>
#include <math.h>
#include <fstream>
using namespace std;

int main(){
ofstream fout;
  fout.open ("consecutive.out");
ifstream fin;
  fin.open ("consecutive.in");

  int n;
fin>>n;
long long x;
queue<long long> stpos;
queue<long long>   lengths;

for (int i=0;i<n;i++){
fin>>x;
int l=2;
double tmp;
int p = l*l- l;
int cnt=0;
while(p <=2*x){
	tmp=((double)x- (double)p/2)/l;
	if (ceilf(tmp) == tmp){
		stpos.push(tmp);
		lengths.push(l);
		cnt++;
	}
	l++;
	p = l*l- l;
}

fout<<cnt<<'\n';
while(!stpos.empty()){
fout<<stpos.front()<<' '<<stpos.front()+lengths.front()-1<<'\n';
stpos.pop();
lengths.pop();
}
}
  fout.close();
return 0;
}