Cod sursa(job #1736487)

Utilizator andreey_047Andrei Maxim andreey_047 Data 1 august 2016 20:20:45
Problema Consecutive Scor 0
Compilator cpp Status done
Runda Arhiva ICPC Marime 0.95 kb
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

int T,nr;
LL N;
bool viz[1000002];

inline LL Sum(LL i,LL j){
  return (j-i+1)*(i+j)/2;
}

struct el{
 LL x,y;
 LL lg;
}a[12005];

inline bool cmp(const el&A,const el&B){
 return A.lg < B.lg;
}

int main(){
    ifstream f("consecutive.in");
    ofstream g("consecutive.out");
    int i;
    LL p;
    f >> T;
    while(T--){
        f >> N; nr = 0;
        N*=2;
        for(i = 1; i*i <= N; ++i)
            if(N%i == 0){
                p = i;
               a[++nr].x = (((N-p*p)/p)+1)/2;
               a[nr].y = (((p*p+N)/p)-1)/2;
               a[nr].lg = a[nr].y-a[nr].x+1;
               if(Sum(a[nr].x,a[nr].y) != N/2 || a[nr].lg <= 1)--nr;
            }
        sort(a+1,a+nr+1,cmp);
        g << nr << '\n';
        for(i = 1; i <= nr; ++i)
            g << a[i].x <<' '<<a[i].y << '\n';
    }
    f.close();
    g.close();
    return 0;
}