c++ - It gives an error for big values -
i solving simple question of finding nth power of 2.it works lower power of n,but fails when try doing higher powers,also,the question have been asked has % 10^9+7 reduce size. if please tell me going wrong.
#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; long long int pro=1; long long int func(int n) { if(n!=1) { pro=pro%1000000007; pro=(2*func(n-1)); return pro; } return 1; } int main() { pro=1; long long int n=555555; long long int x; if(n!=1) x=func(n); else x=1; cout<<x<<endl; } return 0; }
if(n!=1){ x=func(n); }else{ x=1; //this incorrect, should return 2. }
also
long long int func(int n) { if(n!=1) { pro=(2*(func(n-1)%1000000007))%1000000007; return pro; } else return 2; }
Comments
Post a Comment