Cod sursa(job #1710365)

Utilizator relu.draganDragan Relu relu.dragan Data 28 mai 2016 20:50:57
Problema Consecutive Scor 100
Compilator cpp Status done
Runda Arhiva ICPC Marime 1 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <math.h>
using namespace std;
ifstream in("consecutive.in");
ofstream out("consecutive.out");
vector<pair<unsigned long long, unsigned long long>> res;
void solve(unsigned int n)
{
    if (n < 3)
        return;
    unsigned long long nn = n * 2;
    unsigned long long rad = sqrt(nn);
    unsigned long long a;
    unsigned long long aux;

    for (unsigned int k = 2; k <= rad; k++) 
    {
        if (nn % k == 0)
        {
            aux = nn / k - k  + 1;
            if (aux % 2 == 0)
            {
                a = aux / 2;
                res.push_back(make_pair(a, a + k - 1));
            }
        }
    }

}
void afis()
{
    out << res.size() << "\n";
    for (int i = 0; i < res.size(); i++)
        out << res[i].first << " " << res[i].second<< "\n";

}
int main()
{
    int t;
    in >> t;
    for (int i = 0; i < t; i++)
    {
        unsigned int n;
        in >> n;
        solve(n);
        afis();
        res.clear();
    }


}