Cod sursa(job #1708992)

Utilizator UBB_Craciun_Griza_PuscasUBB ATeamHasNoName UBB_Craciun_Griza_Puscas Data 28 mai 2016 10:28:17
Problema Consecutive Scor 100
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.67 kb
#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int nmax = 100005;

int t;
ll n;

vector <pair <ll, ll>> v;


int main() {
    ifstream f("consecutive.in");
    ofstream g("consecutive.out");

    f>>t;
    while(t--) {
        f>>n;

        v.clear();

        for(ll k=2; k*k<=2LL*n; k++) {
            if(2LL*n % k != 0)
                continue;

            ll par = (2LL*n)/k;
            ll x = (par + 1LL - k) / 2LL;

            if(k * (2LL*x + k - 1LL) == 2LL * n) //solutie
                v.push_back(make_pair(x, x+k-1));
        }

        g<<v.size()<<"\n";
        for(auto t:v)
            g<<t.first<<" "<<t.second<<"\n";

    }

    return 0;
}