Problem link:https://www.hackerrank.com/challenges/strange-code/problem
#include <bits/stdc++.h>
using namespace std;
int main()
{
double a,b,c,d;
long long int t,k;
cin>>t;
a=log((t+3)/3);
b=log(2);
k=a/b;
c=3*pow(2,k-1+1);
d=t-(3*(pow(2,k)-1))-1;
if((3*pow(2,k)-1)!=t)
{
cout<<c-d;
}
else
{
cout<<"1";
}
//cout<<c<<" "<<d<<" "<<k;
}
The above code is not working for t=1000000000000
Aucun commentaire:
Enregistrer un commentaire