Cod sursa(job #3306020)

Utilizator Mihai_OctMihai Octavian Mihai_Oct Data 6 august 2025 17:43:30
Problema Consecutive Scor 0
Compilator cpp-64 Status done
Runda Arhiva ICPC Marime 1.17 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("consecutive.in");
ofstream fout("consecutive.out");
long long t, n, d, nr, k, m, rasp[102], i, j;

static inline bool Verif(long long m, long long n) {
    if(m == 1) return false;
    long long a = n / m - (m - 1);
    if(a % 2 == 1) return false;
    return !(a / 2 <= 0);
}

static inline void Test(int _testCur = 0) {
    fin >> n;
    n *= 2;
    d = 1;
    k = 0;
    while(d * d <= n) {
        if(n % d == 0) {
            if(Verif(d, n)) {
                long long a = (n / d - (d - 1)) / 2;
                rasp[++k] = a;
                rasp[++k] = a + d - 1;
            }
            if(Verif(n / d, n)) {
                long long a = (d - (n / d - 1)) / 2;
                rasp[++k] = a;
                rasp[++k] = a + n / d - 1;
            }
        }
        d++;
    }
    fout << k / 2 << "\n";
    for(j = 1; j <= k; j += 2) {
        fout << rasp[j] << " " << rasp[j + 1] << "\n";
    }
}

int main() {
    //ios_base::sync_with_stdio(false);
    fin.tie(nullptr);
    fout.tie(nullptr);

    int t = 1;
    fin >> t;
    while(t--) Test();

    return 0;
}