fork download
  1. import java.util.*;
  2.  
  3. public class Main
  4. {
  5. public static long gcd(long m, long n)
  6. {
  7. if (n != 0)
  8. return gcd(n, m%n);
  9. else
  10. return m;
  11. }
  12.  
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15. Scanner in = new Scanner(System.in);
  16. long m = in.nextLong(), n, result = in.nextLong();
  17.  
  18. for(long i = 2; i <= m; ++i)
  19. {
  20. n = in.nextLong();
  21. result = gcd(result, n);
  22. if (result == 1) m = 1; //same as break
  23. }
  24. System.out.println(result);
  25. }
  26. }
Success #stdin #stdout 0.12s 29340KB
stdin
3	30	738	1926
stdout
6