Pagini recente » Cod sursa (job #2528184) | Cod sursa (job #3269020) | Cod sursa (job #565825) | Cod sursa (job #1709947) | Cod sursa (job #1709533)
#include <stdio.h>
#include <math.h>
int T;
long long N;
long long sums[1000];
FILE* fout;
int result[100];
int maxx;
void generateSums()
{
for(int i=0; i<1000; 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] = (int)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,"%ld",&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;
}