You will be given two integers X and N, you have to calculate XN modulo 1000000007.
Click here to read the complete problem statement.
If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.
You are getting a compilation error.
Looks like the compiler is generating some kind of error known as undefined behavior.
Undefined behavior is something kind of case that was not defined correctly in the header files or does not exist in any kind of documentation.
However, even if I can’t explain how will you handle the problem with C11 compiler now, you can use C++11/14/17 GCC 9.2 to compile to correctly compile it for now.
C++11 or above has additional type overloading versions of pow so they can compile it correctly.
At first glance I thought this could be a an issue with automatic type conversation and the expected type of pow arguments being different from what is provided in the code.
But turns out C11 was not perfectly configured. I have fixed the issue and rejudged all submissions with compilation errors for C11.
Oh! So, it was a misconfigured compiler problem.
I searched for reference to pow and got these declarations. here.
C99
double pow (double base , double exponent);
float powf (float base , float exponent);
long double powl (long double base, long double exponent);
C++98
double pow (double base , double exponent);
float pow (float base , float exponent);
long double pow (long double base, long double exponent);
double pow (double base , int exponent);
long double pow (long double base, int exponent);
C++11
double pow (double base , double exponent);
float pow (float base , float exponent);
long double pow (long double base, long double exponent);
double pow (Type1 base , Type2 exponent);
As you can see, the C++ versions support polymorphism.
I tried to replace int with double but it was still not working.
And thus, I advised him to use a C++ Compiler for now.
#include<stdio.h>
#include<math.h>
int main(void)
{
int X,N;
long double c;
scanf("%d %d",&X,&N);
c=pow(X,N);
long double d=remainder(c,1000000007);
printf("%.Lf\n",d);
return 0;
}