Cod sursa(job #2059458)

Utilizator vvvictorvictor vvvictor Data 7 noiembrie 2017 01:22:11
Problema Consecutive Scor 100
Compilator cpp Status done
Runda Arhiva ICPC Marime 1.04 kb
#include <bits/stdc++.h>
 
#define pb push_back
#define mp make_pair
typedef long long ll;
 
using namespace std;
 
vector<pair<ll, ll>> intervals;
const string file = "consecutive.", 
      in = file + "in", out = file + "out";
 
ifstream fin(in);
ofstream fout(out);
 
ll n;
int t;
 
bool cmp(pair<ll, ll> a, pair<ll, ll> b) 
{
    return (a.second - a.first) < (b.second - b.first);
}
 
inline void go(ll u, ll v)
{
    if ((u - v - 1) % 2 || (u + v -1) % 2)
        return;
     
    intervals.pb(mp((v - u - 1) / 2 + 1, (v + u - 1) / 2));
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    fin >> t;
 
    while (t--)
    {
        fin >> n;
 
        n <<= 1;
        for (int i = 2; i <= sqrt(n); i++)
        {
            if (n % i)
                continue;
 
            go(i, n / i);
        }
 
        fout << intervals.size() << endl;
        sort(intervals.begin(), intervals.end(), cmp);
 
        for (auto& iter : intervals)
            fout << iter.first << " " << iter.second << "\n";
 
        intervals.clear();
    }
 
    return 0;
}