Untitled
raw download clone
C
views 29
,
size 643 b
#include <stdio.h>


long long power(long long x, long long y, long long p)
{
    long long res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    if (x == 0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y /= 2;
        x = ( x * x ) % p;
    }
    return res;
}

int main()
{
   long long x, y, p;
   scanf("%lld%lld%lld", &x, &y, &p);
   printf("%lld\n", power(x, y, p));
   return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.