Cod sursa(job #1710491)

Utilizator CTI_KnightCir Constantin CTI_Knight Data 29 mai 2016 02:02:12
Problema Consecutive Scor 0
Compilator cpp Status done
Runda Arhiva ICPC Marime 0.64 kb
# include <fstream>
# include <algorithm>
# include <cmath>

using namespace std;

ifstream f ( "consecutive.in" );
ofstream g ( "consecutive.out" );

int main()
{
    int n; f >> n;
    vector < pair < int, int > > ans;
    int answer = 0;
    for ( int k = 1; k * (k + 1) / 2 <= n; ++ k ) {
        int s = n - ( k * (k + 1) ) / 2;
        if ( s % (k + 1) == 0 && s / ( k + 1 ) ) {
            ++ answer;
            ans.push_back( make_pair( s / (k + 1), s / (k + 1) + k) );
        }
    }

    g << answer << '\n';
    for ( auto it: ans ) {
        g << it.first << " " << it.second << '\n';
    }

    return 0;
}