1. 


/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem 374 Big Mod
* Link:
*
* @author Miesel Christoph
* @author Seilbeck Robert
* @author Wolfram Andre
* @version 1.0, 05/18/2009
*
* Status : Accepted
* Runtime: 0.120
*/

import java.util.*;
import java.math.*;

public class Main
{
public static void main(String... args)
{
Scanner sc = new Scanner(System.in);
BigInteger B;
int P, N;
while(sc.hasNext())
{
B = new BigInteger(sc.next());
B = B.modPow(new BigInteger(sc.next()), new BigInteger(sc.next()));
System.out.println(B.toString());
}
}
}

2.

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #374 Big Mod
* Link: http://icpcres.ecs.baylor.edu/onlinejudge/index.php?option=com_onlinejudge&Itemid=8&category=13&page=show_problem&problem=1103
*
* @author Fabian Seidl
* @author Marcel Sachse
* @version 1.0, 29/04/2009
*
* Status : Accepted
* Runtime: 0.080
*/

import java.io.*;
import java.util.Scanner;
import java.math.*;

public class Main
{

public static void main(String[] args) throws Exception
{

BufferedInputStream bInput = new BufferedInputStream(System.in);
Scanner scanner = new Scanner(bInput);

Writer out = new BufferedWriter(new PrintWriter(System.out));

while(scanner.hasNextInt())
{

// Variante1 fertige BigInteger Methode
BigInteger b = scanner.nextBigInteger();
BigInteger p = scanner.nextBigInteger();
BigInteger m = scanner.nextBigInteger();

BigInteger r = b.modPow(p, m);

out.write(r+"\n");



}
out.close();
}
}