Cod sursa(job #1837464)

Utilizator felixiPuscasu Felix felixi Data 29 decembrie 2016 18:46:08
Problema Consecutive Scor 100
Compilator cpp Status done
Runda Arhiva ICPC Marime 1.3 kb
#include <fstream>
#include <algorithm>
#include <utility>
#include <vector>
 
#define int long long int
using namespace std;
 
pair <int, int> get_pair(int n, int N) {
    int a = ((2 * N) / n - n + 1);
    if (a & 1)
        return make_pair(0, 0);
    a /= 2;
 
    if (a >= 1)
        return make_pair(n, a);
    else
        return make_pair(0, 0);
}
 
ifstream cin("consecutive.in");
ofstream cout("consecutive.out");
 
void solve(int N) {
    vector <pair <int, int> > sol;
 
    pair <int, int> p;
    for (int n = 1; n * n <= 2 * N; ++ n)
        if ((2 * N) % n == 0) {
            p = get_pair(n, N);
            if (p.first)
                sol.push_back(p);
 
            if (n * n != N) {
                p = get_pair((2 * N) / n, N);
                if (p.first)
                    sol.push_back(p);
            }
        }
 
    sort(sol.begin(), sol.end());
 
    cout << sol.size() - 1 << '\n';
    for (vector <pair <int, int> > :: iterator it = sol.begin() + 1; it != sol.end(); ++ it)
        cout << it -> second << ' ' << it -> first + it -> second - 1 << '\n';
}
 
signed main()
{
    int t = 0;
    cin >> t;
 
    while (t --) {
        int n = 0;
        cin >> n;
 
        solve(n);
    }
 
    cin.close();
    cout.close();
    return 0;
}