Cod sursa(job #2708715)

Utilizator theo2003Theodor Negrescu theo2003 Data 19 februarie 2021 11:36:36
Problema Consecutive Scor 0
Compilator cpp-64 Status done
Runda Arhiva ICPC Marime 1.05 kb
#include <fstream>
#include <cmath>
#include <vector>
using namespace std;
vector<int> out;
ifstream cin("consecutive.in");
ofstream cout("consecutive.out");
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while(t--){
        out.resize(0);
        int n, ml;
        cin>>n;
        for(int l = 2;l<=n;l++){
            //n = l * (2*s + l - 1) / 2
            //s = n/l - l/2 + 1/2
            if((n%l == 0) && (l%2 == 1)){
                out.push_back(n/l - (l-1)/2);
                out.push_back(n/l - (l-1)/2 + l - 1);
            }else if(((n%l)*2 == l) && (l%2 == 0)){
                out.push_back(n/l + 1 - l/2);
                out.push_back(n/l + 1 - l/2 + l - 1);
            }
            if(out[out.size() - 2] <= 0){
                out.resize(out.size() - 2);
                break;
            }
        }
        cout<<out.size()/2<<'\n';
        for(int x = 0;x<out.size();x+=2){
            cout<<out[x]<<' '<<out[x+1]<<'\n';
        }
    }
    return 0;
}