Cod sursa(job #1708964)

Utilizator UNIBUC_Costan_Iordache_MagureanuGangster Teddy Bears Trio UNIBUC_Costan_Iordache_Magureanu Data 28 mai 2016 10:23:57
Problema Consecutive Scor 100
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.77 kb
#include<cstdio>
#include<vector>
#include<utility>
using namespace std;

vector<pair<int,int> > ans;

int main(){
    freopen ("consecutive.in","r",stdin);
    freopen ("consecutive.out","w",stdout);
    int t,i;
    long long n,k,aux;

    scanf ("%d",&t);

    for(;t>0;t--){
        scanf ("%lld",&n);
        n*=2;
        k=2;
        aux=1;
        while(k*k<=n &&aux>0){
            if (n%k==0){
                aux=n/k+1-k;
                if (aux>0 &&(aux&1)==0){
                    aux/=2;
                    ans.push_back(make_pair(aux,aux+k-1));
                }
            }
            k++;
        }

        printf ("%d\n",ans.size());
        for(i=0;i<ans.size();i++)
            printf ("%d %d\n",ans[i].first,ans[i].second);
        ans.clear();
    }
    return 0;
}