Cod sursa(job #1709691)

Utilizator UPT_SyntaxErrorUPT SyntaxError UPT_SyntaxError Data 28 mai 2016 13:28:12
Problema Consecutive Scor 0
Compilator c Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 1.04 kb
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int i,k,  t,  a[70000],b[70000], x;
long n;

int main()
{
    freopen("consecutive.in", "r", stdin);
    freopen("consecutive.out", "w", stdout);

    scanf("%d", &t);

    for(k=0; k<t; k++)
    {
        scanf("%ld", &n);
        x = 0;

        //int M = ((int)sqrt(1.0+8*n)-1)/2 + 5;
        int M = (sqrt(1+8*n)-1)/2 + 10;

        for(i = 2; i<M; i++)
        {
            if(i%2==0)
            {
                if(((n%i)==(i/2)) && (n/i - (i / 2 -1)>0))
                {
                    a[x] = n/i - (i / 2 -1);
                    b[x] = n/i + i/2;
                    x++;
                }
            }
            else
            {
                if(((n%i)==0) && (n/i - i/2>0))
                {
                    a[x] = n/i - i/2;
                    b[x] = n/i + i/2;
                    x++;
                }
            }
        }

        printf("%d\n",x);
        for(i=0; i<x; i++)
            printf("%d %d\n", a[i], b[i]);

        printf("\n");

    }

    return 0;
}