Cod sursa(job #1709141)

Utilizator UBB_ABAUBB InczeBakoBeiland UBB ABA UBB_ABA Data 28 mai 2016 11:01:30
Problema Consecutive Scor 100
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.98 kb
#include <fstream>
#include <utility>
#include <list>
using namespace std;

typedef pair<int, int> PII;

int main()
{
    ifstream fin("consecutive.in");
    ofstream fout("consecutive.out");

    int t; fin>>t;

    PII lst[50000];

    while(t--){
        int n; fin>>n;

        int cnt=0;

        for(long long nr=2; nr*(nr+1)/2<=n; ++nr){
            if(nr%2==0){
                int k=nr/2;
                if(n%k==0){
                    int x = n/k - (2*k-1);
                    if(x>0 && x%2==0){
                        int a = x/2;
                        lst[cnt++]=PII(a,a+2*k-1);
                    }
                }
            }
            else{ //nr==2k+1
                if(n%nr==0){
                    int k=nr/2;
                    int a = n/nr - k;
                    if(a>0) lst[cnt++]=PII(a,a+2*k);
                }
            }
        }


        fout<<cnt<<'\n';
        for(int i=0;i<cnt;++i){
            fout<<lst[i].first<<' '<<lst[i].second<<'\n';
        }
    }
}