Cod sursa(job #1975414)

Utilizator FahranCristian Matei Fahran Data 30 aprilie 2017 19:35:05
Problema Consecutive Scor 0
Compilator cpp Status done
Runda Arhiva ICPC Marime 0.92 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <stack>
using namespace std;

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

int T;
long int N,p,q;
int i,ct=0;
stack<long> s;

int main()
{
    f>>T;
    for (i=1; i<=T; i++)
    {
        f>>N;
        if((N&(N-1)) == 0)
        {
            g<<0<<endl;
        }
        else
        {
            for(p = N/2; p>=2; p--)
            {
                if (2*N%p== 0)
                {
                    if((2*N/p-p)%2 == 1)
                    {
                        s.push(p);
                        ct++;
                    }

                }
            }
            g<<ct<<endl;
            ct=0;
            while(!s.empty())
            {
                p=s.top();
                s.pop();
                g<<(2*N/p-p+1)/2<<" "<<(2*N/p-p+1)/2+p-1<<endl;
            }
        }

    }
}