Cod sursa(job #1709268)

Utilizator UPB_itslupusUPB Crecana Cristache Jercaianu UPB_itslupus Data 28 mai 2016 11:33:11
Problema Consecutive Scor 0
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 1.05 kb
#include<iostream>
#include<fstream>
#include<vector>
#include<math.h>

using namespace std;

ifstream fin("consecutive.in");
ofstream fout("consecutive.out");

int T, N;

int main()
{
    fin >> T;
    for (int t = 0; t < T; t++) {
        fin >> N;
        vector<int> sol_low;
        vector<int> sol_high;
        for (int i = 1; i < N/2 + 1; i++) {
            int c = 2 * N + i * i - i;
            int aux = 1 + 4 * c;
            //cout << i << " " <<aux<<"\n";
            int s = round(sqrt(aux));
            if (s * s == aux) {
                int b = (-1 + s);
                if (b % 2 )
                    continue;
                b = b / 2;
                //cout << i << " " << aux << " " << b<<"\n";
                if (b > i && b <= N/2 + 1) {
                    sol_high.push_back((-1 + s) / 2); 
                    sol_low.push_back(i);
                }
            }
        }

        fout << sol_low.size() << '\n';
        for (int i = 0; i < sol_low.size(); i++) {
            fout << sol_low[i] << " " << sol_high[i] << '\n';
        }
    }
}