Using pow() for large number
Posted
by
g4ur4v
on Stack Overflow
See other posts from Stack Overflow
or by g4ur4v
Published on 2012-09-03T20:56:15Z
Indexed on
2012/09/03
21:38 UTC
Read the original article
Hit count: 202
c++
|data-type-conversion
I am trying to solve a problem, a part of which requires me to calculate (2^n)%1000000007 , where n<=10^9. But my following code gives me output "0" even for input like n=99.
Is there anyway other than having a loop which multilplies the output by 2 every time and finding the modulo every time (this is not I am looking for as this will be very slow for large numbers).
#include<stdio.h>
#include<math.h>
#include<iostream>
using namespace std;
int main()
{
unsigned long long gaps,total;
while(1)
{
cin>>gaps;
total=(unsigned long long)powf(2,gaps)%1000000007;
cout<<total<<endl;
}
}
© Stack Overflow or respective owner