Cod sursa(job #2201816)

Utilizator robery567Robert Mihai Colca robery567 Data 6 mai 2018 11:01:54
Problema Consecutive Scor 0
Compilator cpp Status done
Runda Arhiva ICPC Marime 1.1 kb
#include <iostream>
#include <fstream>
#include <vector>

namespace iordania {
    std::ifstream citire("consecutive.in");
    std::ofstream scriere("consecutive.out");
};


using namespace iordania;

int main() {
    long long t, n, foundNumber, j;
    long double calculatedVal;
    std::vector<std::pair<long long, long long>> foundNumbers;

    citire >> t;

    for (int i = 0; i < t; ++i) {
        citire >> n;
        j = 2;
        foundNumber = 3;

        while (foundNumber <= n) {
            calculatedVal = (n - (long double)foundNumber)/j + 1;

            if (calculatedVal - (long long)calculatedVal == 0) {
                foundNumbers.emplace_back(std::make_pair(calculatedVal, calculatedVal+j-1));
            }

            ++j;
            foundNumber += j;
        }


        unsigned long numbersOfElement = foundNumbers.size();

        if (numbersOfElement) {
            scriere << numbersOfElement << '\n';

            for (auto it : foundNumbers) {
                scriere << it.first << " " << it.second << '\n';
            }

            foundNumbers.clear();
        }
    }

    return 0;
}