Cod sursa(job #1709736)

Utilizator Echipa_PietrelorMancam pietre Echipa_Pietrelor Data 28 mai 2016 13:41:53
Problema Consecutive Scor 100
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 1.23 kb
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>

#define x first
#define y second
#define LL long long

using namespace std;

vector <LL> D;
vector < pair<LL, LL> > sol;
LL a, lim;

inline LL cmp(pair<LL, LL> a, pair<LL, LL> b){
    return a.x > b.x;
}

int main(){
    int T;
    freopen("consecutive.in", "r", stdin);
    freopen("consecutive.out", "w", stdout);
    scanf("%d", &T);
    while(T--){
        scanf("%lld", &a);
        lim = (LL) sqrt((double)2 * a);
        for(LL i = 1; i <= lim; ++ i)
            if((2 * a) % i == 0){
                D.push_back(i);
                D.push_back(2 * a / i);
            }
        if(lim * lim == 2 * a)
            D.pop_back();
        for(LL i = 0; i < D.size(); ++ i)
            if(D[i] != 1 && (2 * a - D[i] * (D[i] - 1)) % (2 * D[i]) == 0 && (2 * a - D[i] * (D[i] - 1)) / (2 * D[i]) > 0)
                sol.push_back(make_pair((2 * a - D[i] * (D[i] - 1)) / (2 * D[i]), D[i]));
        sort(sol.begin(), sol.end(), cmp);
        printf("%d\n", sol.size());
        for(LL i = 0; i < sol.size() ; ++ i)
            printf("%lld %lld\n", sol[i].x, sol[i].y + sol[i].x - 1);
        sol.clear();
        D.clear();
    }
    return 0;
}