fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class NodeTransitionFunction
  9. {
  10. int exp, KVal;
  11. NodeTransitionFunction(int exp, int KVal){
  12. this.exp = exp;
  13. this.KVal = KVal;
  14. }
  15.  
  16. int apply(int val){
  17. int ans = 1;
  18. int e = exp;
  19. while(e != 0){
  20. if(e % 2 == 0){
  21. val = (val * val) % KVal;
  22. e = e / 2;
  23. }
  24. else{
  25. ans = (ans * val) % KVal;
  26. e--;
  27. }
  28. }
  29. return ans;
  30. }
  31. public static void main (String[] args) throws java.lang.Exception
  32. {
  33. NodeTransitionFunction x = new NodeTransitionFunction(3, 12);
  34. System.out.print(x.apply(5));
  35.  
  36. }
  37. }
Success #stdin #stdout 0.04s 2184192KB
stdin
Standard input is empty
stdout
5