#!/usr/bin/perl
use Math::GMP;


my $x = new Math::GMP ($ARGV[0]);
my $r = new Math::GMP 1;
my $m = new Math::GMP ($ARGV[2]);
my $n = $ARGV[1];
for( my $i = 0; $i < $n; $i++ ) {
   $r = ($r * $x ) % $m;
   $x = ($x * $x ) % $m;
}
print "$r\n"; 
