Cod sursa(job #1708955)

Utilizator forsakenAweUNIBUC Suditu Cornoiu Chihai forsakenAwe Data 28 mai 2016 10:22:00
Problema Consecutive Scor 0
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.9 kb
#include <bits/stdc++.h>
using namespace std;


int main()
{

    int T;
    cin>>T;
    while(T--)
    {
        int n;
        cin>>n;

        vector<pair<int,int> > v;
        int diff;
        long long nn  = 2LL * n;

        long long lim = (int)sqrt(nn) + 1; lim = max(lim, nn);
        for(diff = 1; diff <= lim; diff++)
        {
                int tmp = diff + 1;
                if (nn % tmp != 0) continue;
                tmp = nn / tmp;

                if ((tmp + diff) & 1) continue;
                long long b = tmp + diff;
                b /= 2;
                long long a = tmp - b;
                if (a <= 0) continue;

                v.push_back(make_pair(a,b));
        }
        cout << v.size() << '\n';
        for(int i = 0; i < v.size(); i++) {
            cout << v[i].first << ' ' << v[i].second << '\n';
        }
    }





    return 0;
}