Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- const ll mod=1e9+7;
- ll pw[100],dp[100][3][3],n;
- int DP(int x,bool y,bool z){
- if(x==-1)return 1;
- ll ret=dp[x][y][z];if(ret!=-1)return ret;
- ret=0;
- bool bit=((bool)(n&(1ll<<x)));
- if(y&&z)return ret=pw[x+1];
- if(!y&&!z){
- if(bit){
- ret+=DP(x-1,1,0)%mod;
- ret+=DP(x-1,0,1)%mod;
- ret+=DP(x-1,1,1)%mod;
- }
- else{
- ret+=DP(x-1,0,0)%mod;
- }
- }
- if(y&&!z){
- if(bit){
- ret+=(DP(x-1,y,1)*2)%mod;
- ret+=DP(x-1,y,0)%mod;
- }
- else{
- ret+=(DP(x-1,y,z)*2)%mod;
- }
- }
- if(!y&&z){
- if(bit){
- ret+=(DP(x-1,1,z)*2)%mod;
- ret+=DP(x-1,0,z)%mod;
- }
- else{
- ret+=(DP(x-1,y,z)*2)%mod;
- }
- }
- ret%=mod;
- return ret;
- }
- int main(){
- pw[0]=1;
- for(int i=1;i<=61;i++)pw[i]=(pw[i-1]*3)%mod;
- memset(dp,-1,sizeof(dp));
- cin>>n;
- cout<<DP(61,0,0)<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement