Cod sursa(job #1709256)

Utilizator UPT_SyntaxErrorUPT SyntaxError UPT_SyntaxError Data 28 mai 2016 11:29:55
Problema Consecutive Scor 0
Compilator c Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.95 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;

        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]);

    }

    return 0;
}