Cod sursa(job #2940703)

Utilizator T1raduTaerel Radu Nicolae T1radu Data 16 noiembrie 2022 10:38:29
Problema Consecutive Scor 0
Compilator cpp-64 Status done
Runda Arhiva ICPC Marime 1.23 kb
#include <fstream>
#include <map>
using namespace std;
ifstream fin("consecutive.in");
ofstream fout("consecutive.out");
int t;
long long n;
map<int, pair<int,int> > M;
int main()
{
    fin >> t;
    for(int i=1;i<=t;i++)
    {
        fin >> n;
        long long k=0;
        long long p=n&(-n);
        n/=p;
        for(int j=1;j*j<=n;j+=2)
        {
            if(n%j==0)
            {
                long long d1=j;
                long long d2=(2*n)/j;
                int st=d2-d1+1;
                if(j!=1)
                {
                    if(st%2==0)
                    {
                        k++;
                        M[d1]=make_pair(st/2,st/2+d1-1);
                    }
                }
                d1=p*2*j;
                d2=(2*n)/d1;
                if(d1>d2) swap(d1,d2);
                st=d2-d1+1;
                if(st%2==0)
                {
                    k++;
                    M[d1]=make_pair(st/2,st/2+d1-1);
                }
            }
        }
        fout << k << "\n";
        for(map<int, pair<int,int> >::iterator it=M.begin();it!=M.end();++it)
            fout << (*it).second.first << " " << (*it).second.second << "\n";
    }
    return 0;
}