Cod sursa(job #2002960)

Utilizator lupulescu2001Lupulescu Vlad lupulescu2001 Data 21 iulie 2017 12:16:24
Problema Ridicare la putere in timp logaritmic Scor 60
Compilator cpp Status done
Runda Arhiva educationala Marime 1.04 kb
#include<fstream>
#include<algorithm>
#define mod 1999999973
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long v[35];
int main()
{
    long long a,b,x,l=1,n,i,sol=0,y,z,k,f;
    fin>>a>>b;
    a=a%mod;
    x=b;
    n=a;
    while(x>0)
    {
        if(x%2==1)
        {
            y=n;
            f=sol;
            if(sol==0)
                k=1;
            else
                k=sol;
            while(y>0)
            {
                if(y%2==1)
                {
                    sol=sol+k;
                }
                k*=2;
                k=k%mod;
                sol=sol%mod;
                y=y/2;
            }
            sol=sol-f;
        }
        y=n;
        k=n;
        n=0;
         while(y>0)
            {
                if(y%2==1)
                {
                    n=n+k;
                }
                k*=2;
                k=k%mod;
                n=n%mod;
                y=y/2;
            }
        x=x/2;
    }
    fout<<sol;
}