I'm trying to calculate, for 0 < n ≤ 10⁹
, the value of
re=(2^n)%1000000007
I wrote this code:
int main()
{
int n,i,re=1;
scanf("%d",&n);
for(i=0; n>i; i++) re=(2*re)%1000000007;
printf("%d",re);
}
When n
is 10⁹, my code takes too long.
What can I do to make it faster?