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 int gcd(int a, int b)
  11. {
  12. while(b!=0)
  13. {
  14. int temp=a%b;
  15. a=b;
  16. b=temp;
  17. }
  18. return a;
  19. }
  20. public static void main (String[] args) throws java.lang.Exception
  21. {
  22. // your code goes here
  23. Scanner sc=new Scanner(System.in);
  24. int n=sc.nextInt();
  25. int a[]=new int [n];
  26. for(int i=0;i<n;i++)
  27. a[i]=sc.nextInt();
  28.  
  29. int ans=a[0];
  30. for(int i=0;i<n;i++)
  31. ans=gcd(a[i],ans);
  32.  
  33. System.out.println(ans);
  34.  
  35.  
  36.  
  37.  
  38. }
  39. }
Success #stdin #stdout 0.11s 54432KB
stdin
5
5 5 15 20 255
stdout
5