/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package core;

import java.awt.Container;
import java.util.Collection;
import java.util.List;

/**
 *
 * @author jirka
 */
public class SuperModulo
{

    public static int Modulo(int A, int E, int N)
    {
       String s = Integer.toString(E, 2);
       String vyst="";
       String vyst2="";

       int len = s.length();
       long pom = 1;
       int[] arr = new int[s.length()+1];
       arr[0] = A;
       for (int i=0; i< s.length(); i++){
           arr[i+1]=arr[i]*arr[i] % N;
       }
       for (int i=0; i< s.length(); i++){
           //arr[i]=arr[i]*(s.charAt(len-1));
          // len--;
           if (s.charAt(len-1)=='0'){
           //    arr[i]=arr[i]*0;
           }
           else{
               pom = pom * arr[i];
           }
           len--;

           //vyst2 = vyst2 + " "+ arr[i];
       }
       int pom2 = (int) (pom % N);

       return pom2;

    }
}
