fork(3) 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. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int n = 1235;
  13. int x = 123;
  14. long time = System.nanoTime();
  15. System.out.println(power(n,x) + " Time: " + (System.nanoTime()- time));
  16.  
  17. time = System.nanoTime();
  18. System.out.println(Math.pow(n,x) + " Time: " + (System.nanoTime()- time));
  19. }
  20. public static long power(long n, int x){
  21. long pow = 1;
  22. long exp = n;
  23. while(x>0){
  24. if((x & 1) == 1){
  25. pow*=exp;
  26. }
  27. exp*= exp;
  28. x = x>>1;
  29. }
  30. return pow;
  31. }
  32. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
-8356899175023020885 Time: 84073
Infinity Time: 1262488