Pagini recente » Cod sursa (job #1420787) | Cod sursa (job #2460507) | Cod sursa (job #1577088) | Cod sursa (job #3138095) | Cod sursa (job #1710655)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream in ("consecutive.in");
ofstream out ("consecutive.out");
pair <int,int> v[100000];
int dif[1000000];
int poz[1000000];
short sum (int poz1,int poz2,int nr)
{
unsigned long long s=0;
s=(unsigned long long)poz2*(poz2+1)/2;
if(poz1>1)
s=s-(unsigned long long)poz1*(poz1-1)/2;
if(s==nr)
return 1;
else if(s<nr) return 2;
else
return 0;
}
int main()
{
int t,n,k=0;
in>>t;
int i,poz1,poz2;
for(i=1;i<=t;i++)
{
in>>n;
for(poz1=1;sum(poz1,poz2,n);poz1++)
for(poz2=poz1+1;sum(poz1,poz2,n);poz2++)
if(sum(poz1,poz2,n)==1)
{
v[k+1].first=poz1;
v[k+1].second=poz2;
dif[k+1]=poz2-poz1;
poz[dif[k+1]]=k+1;
k++;
}
out<<k<<'\n';
sort(dif+1,dif+k+1);
for(int j=1;j<=k;j++)
{
out<<v[poz[dif[j]]].first<<' '<<v[poz[dif[j]]].second<<'\n';
}
k=0;
out<<'\n';
}
return 0;
}