Cod sursa(job #2247281)

Utilizator andreisontea01Andrei Sontea andreisontea01 Data 28 septembrie 2018 12:18:14
Problema Consecutive Scor 0
Compilator cpp Status done
Runda Arhiva ICPC Marime 0.78 kb
#include <fstream>
#include <iostream>
#include <vector>

using namespace std;

vector<int> st, dr;

int main()
{
    ifstream fin("consecutive.in");
    ofstream fout("consecutive.out");
    int t;
    fin >> t;
    while(t){
        long long n;
        fin >> n;
        for(long long x = 2; x * x <= 2 * n; ++x){
            int left = 2 * n - x * x + x;
            if(left % (2 * x) == 0){
                left /= 2 * x;
                if(left > 0){
                   st.push_back(left);
                   dr.push_back(left + x - 1);
                }
            }
        }
        fout << st.size() << "\n";
        for(int i = 0; i < int(st.size()); ++i)
            fout << st[i] << " " << dr[i] << "\n";
        st.clear();
        dr.clear();
        t--;
    }
    return 0;
}