Codeforces celebrates 10 years! We are pleased to announce the crowdfunding-campaign. Congratulate us by the link https://codeforces.com/10years. ×

help in understanding exactly where to apply  modulo operator
Difference between en1 and en2, changed 723 character(s)
* Given an integer n, find and return the n'th magic number↵
* A magic number is defined as a number which can be expressed as a power of 7 or sum of unique powers of 7↵
* First four magic numbers are  7 ,  49 ,  56 (7 + 49),  343,etc .↵
constraint 1<=n<=pow(10,18)↵
i have implemented the solution as follows:↵

#include<bits/stdc++.h>↵
#define ll unsigned long long int↵
ll mod=1000000007;↵
using namespace std;↵
int main(){↵
ll n;↵
cin>>n;↵
ll count=1,sum=0;↵
while(n>0){↵
ll temp=n%2;↵
n/=2;↵
count++;↵
}↵
cout<<sum;
↵
https://www.hackerrank.com/contests/csi-anits/challenges/lucky-seven-2/submissions/code/1318214667

}
but it gives me wrong answer,the only difference is that when calculating the value of add we need to apply mod;and the solution is as follows:↵

#include<bits/stdc++.h>↵
#define ll unsigned long long int↵
ll mod=1000000007;↵
using namespace std;↵
int main(){↵
ll n,p=1;↵
cin>>n;↵
ll count=1,sum=0;↵
while(n>0){↵
ll temp=n%2;↵
p=(p*7)%mod;↵
if(temp==1)↵
sum=(sum%mod+p%mod)%mod;↵
n/=2;↵
}↵
cout<<sum;↵
}
https://www.hackerrank.com/contests/csi-anits/challenges/lucky-seven-2↵

how will we know where to apply a mod operator..pls help.↵

#### History

Revisions Rev. Lang. By When Δ Comment
en3 rprudhvi590 2019-12-07 14:33:05 162
en2 rprudhvi590 2019-12-07 14:15:35 723
en1 rprudhvi590 2019-12-07 14:01:57 1290 Initial revision (published)