class Solution{

public:

//You need to complete this fucntion

long long power1(int N,int R){

if(R==0)

return 1;

else

return N*power1(N,R-1);

}

long long power(int N,int R)

{

//Your code here

```
return power1(N,R)%1000000007;
}
```

};

class Solution{

public:

//You need to complete this fucntion

long long power1(int N,int R){

if(R==0)

return 1;

else

return N*power1(N,R-1);

}

long long power(int N,int R)

{

//Your code here

```
return power1(N,R)%1000000007;
}
```

};

You need to mod it after every recursive call otherwise it will lead to overflow.

return (N*power1(N, R-1)) % 1000000007;

This will work fine.

Note: Depending on the constraints of the problem, you might have to use fast exponentiation to pass all the test cases. It can calculate N^R in log(R)base2 time.