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 Ideone
  9. {
  10. static long power(int b,int i){
  11. long num;
  12. if(i==1)
  13. return b;
  14. else if(i%2==0){
  15. num=(long)Math.pow(power(b,i/2),2);
  16. if(num>=1000000007)
  17. num%=1000000007;
  18. return num;
  19. }
  20. else{
  21. num=b*(long)Math.pow(power(b,(i-1)/2),2);
  22. if(num>=1000000007)
  23. num%=1000000007;
  24. return num;
  25. }
  26. }
  27.  
  28. public static void main (String[] args) throws java.lang.Exception
  29. {
  30. System.out.println(power(2, 999999999));
  31. System.out.println(power(2, 1000000000));
  32. }
  33. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
646458006
477022294