Editorial
How to compute faster than ? For example,
It can be noted that , for example .
For odd powers, we use the formula , for example .
The following recursive formula gives us an solution:
In an iterative implementation, the case when and is a large integer should be handled separately. For example, when and , computing would require iterations, which would result in a Time Limit.
Algorithm realization
The function f computes the value of .
long long f(long long x, long long n) { if (n == 0) return 1; if (n % 2 == 0) return f(x * x, n / 2); return x * f(x, n - 1); }
The main part of the program. Read the input data.
scanf("%lld %lld",&x,&n);
Compute and print the answer .
res = f(x,n); printf("%lld\n",res);