Cod sursa(job #1710416)

Utilizator andreicoman299Coman Andrei andreicoman299 Data 28 mai 2016 22:11:12
Problema Consecutive Scor 0
Compilator cpp Status done
Runda Arhiva ICPC Marime 0.76 kb
#include <stdio.h>
#include <stdlib.h>

int q[100000][2], ind;
int main(){
    int t, i, n, k;
    FILE*fi,*fo;
    fi=fopen("consecutive.in","r");
    fo=fopen("consecutive.out","w");
    fscanf(fi,"%d", &t);
    for(i=0;i<t;i++){
        fscanf(fi,"%d", &n);
        n*=2;
        ind=0;
        k=2;
        while(k*k<=n){
            if(n%k==0){
                if((n/k-(k+1))%2==0){
                    q[ind][0]=(n/k-(k+1))/2+1;
                    q[ind][1]=q[ind][0]+k-1;
                    ind++;
                }
            }
            k++;
        }
        fprintf(fo,"%d\n", ind);
        for(int j=0;j<ind;j++){
            fprintf(fo,"%d %d\n", q[j][0], q[j][1]);
        }
    }
    fclose(fi);
    fclose(fo);
    return 0;
}