Cod sursa(job #1709077)

Utilizator UPB_ShiftMyBitsUPB Mirea Avram Boaca UPB_ShiftMyBits Data 28 mai 2016 10:49:15
Problema Consecutive Scor 0
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.76 kb
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

void solve(unsigned int n) {
    unsigned int k = 0, p = 1, cnt = 0;
    vector<pair<unsigned int, unsigned int>> sol;
    for (unsigned int x = 2; x * (x + 1) <= 2 * n; ++x) {
        p = x * (x + 1) / 2;
        if ((n - p) % x == 0) {
            k = (n - p) / x;
            cnt++;
            sol.emplace_back(k + 1, k + x);
        }
    }
    cout << sol.size() << '\n';
    for (const auto& p : sol) {
        cout << p.first << ' ' << p.second << '\n';
    }
}

int main() {
#ifdef INFOARENA
    ifstream cin("consecutive.in");
    ofstream cout("consecutive.out");
#endif
    int T;
    cin >> T;
    while (T--) {
        int N;
        cin >> N;
        solve(N);
    }
    return 0;
}