Pagini recente » Cod sursa (job #253466) | Cod sursa (job #1830973) | Cod sursa (job #2394010) | Cod sursa (job #1708937) | Cod sursa (job #1709508)
#include <stdio.h>
#include <math.h>
int T;
long N;
long sums[1000000];
FILE* fout;
int result[1000];
int maxx;
void generateSums()
{
for(int i=0; i<1000000; i++)
{
sums[i] = (i*(i+1))/2;
}
}
void calculate()
{
for(int i=1; i<N/2; i++)
{
if(sums[i]>=N)
return;
float y = (float)(N-sums[i]);
float x = (float)(y/((float)i+1));
if(x == floor(x))
{
result[2*maxx] = x;
result[2*maxx+1] = (int)x+i;
maxx++;
}
}
}
int main()
{
FILE *fin = fopen("consecutive.in", "r");
fout = fopen("consecutive.out", "w");
int v = fscanf(fin,"%d", &T);
generateSums();
for(int i=0; i<T; i++)
{
maxx = 0;
fscanf(fin,"%d",&N);
calculate();
fprintf(fout,"%d\n", maxx);
for(int k=0; k<maxx; k++)
{
fprintf(fout,"%d %d\n",result[2*k], result[2*k+1]);
}
}
fclose(fin);
fclose(fout);
return 0;
}