I want to calculate 2^N for large value of N i.e. upto 10^9 with mod operation. Used an iterative approach but its taking a lot of time for the input 10^8.
for(long i=1;i<=n;i++){
res=(res*2)%1000000007
}
Its taking time in calculating for n=10^8 and above.