Pagini recente » Cod sursa (job #115778) | Cod sursa (job #486304) | Cod sursa (job #2254317) | Cod sursa (job #1465050) | Cod sursa (job #1709669)
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
/*
unsigned long long N,T;
unsigned long long x[100000],y[100000];
unsigned long long cautbin(unsigned long long lung, unsigned long long fin,unsigned long long start)
{
unsigned long long m,p,u,calc1,calc2;
p=start;
u=fin;
while(p<=u)
{
m=(p+u)/2;
calc2=m-lung;
calc1=(m*(m+1)/2)-(calc2*(calc2+1)/2);
if(calc1==N) return m;
if(calc1>N)
{
u=m-1;
}
else p=m+1;
}
return 0;
}
*/
unsigned long long T, N, x[10000], y[10000];
int main()
{
ifstream f("consecutive.in");
ofstream g("consecutive.out");
f >> T;
unsigned long long i, lungime, rez, countt, calc, j, last, first, S, h, mijloc, mijloc2;
for (i = 1;i <= T;i++)
{ countt=0;
f>>N;
first = (sqrt(1 + 8 * N) - 1) / 2;
if (N % 2 == 0)
{
lungime = 3;
}
else
{
countt++;
x[1] = N / 2;
y[1] = x[1] + 1;
lungime = 3;
}
while (lungime <= first && lungime!=0)
{
mijloc = N / lungime;
if (lungime % 2 == 1)
{
if (N%lungime == 0)
{
countt++;
x[countt] = mijloc - lungime / 2;
y[countt] = mijloc + lungime / 2;
}
}
else
{
mijloc2 = mijloc + 1;
rez = (mijloc + mijloc2)*(lungime / 2);
if (N == rez)
{
countt++;
x[countt] = mijloc - lungime / 2 + 1;
y[countt] = mijloc + lungime / 2;
}
}
lungime++;
if (lungime % 2 == 0)
{
h = lungime / 2;
if (h % 2 == 1 && N % 2 == 0) lungime++;
if (h % 2 == 0 && N % 2 == 1) lungime++;
}
}
g << countt << '\n';
for (j = 1;j <= countt;j++)
{
g << x[j] << " " << y[j] << '\n';
}
}
f.close();
g.close();
return 0;
}
/*
int main()
{
ifstream f("consecutive.in");
ofstream g("consecutive.out");
f>>T;
unsigned long long i,lungime,rez,countt,calc,j,maximmm=0,last,first,S,h;
for(i=1;i<=T;i++)
{
f>>N;
first=(sqrt(1+8*N)-1)/2;
last=N/2+1;
countt=0;
if(N%2==0)
{
lungime=3;
}
else
{
countt++;
x[1]=N/2;
y[1]=x[1]+1;
lungime=3;
}
while(lungime<=first)
{
rez=cautbin(lungime,last,first);
if(rez!=0)
{
countt++;
y[countt]=rez;
x[countt]=rez-lungime+1;
last=rez-1;
}
lungime++;
if(lungime%2==0)
{
h=lungime/2;
if(h%2==1&&N%2==0) lungime++;
if(h%2==0&&N%2==1) lungime++;
}
}
g<<countt<<'\n';
for(j=1;j<=countt;j++)
{
g<<x[j]<<" "<<y[j]<<'\n';
}
}
return 0;
}
*/