fork download
  1. <?php
  2. $input = trim(fgets(STDIN));
  3. $values = explode(" ", $input);
  4. $isMax = 0;
  5.  
  6. for ($i = 1; $i <= $values[0]; $i++) {
  7. if ($values[0] % $i == 0) {
  8. $array1[] = $i;
  9. }
  10. }
  11.  
  12. for ($j = 1; $j <= $values[1]; $j++) {
  13. if ($values[1] % $j == 0) {
  14. $array2[] = $j;
  15. }
  16. }
  17.  
  18. $commonValues = array_intersect($array1, $array2);
  19.  
  20. print_r($commonValues);
  21. foreach ($commonValues as $max) {
  22. if ($max > $isMax) {
  23. $isMax = $max;
  24. }
  25. }
  26. echo $isMax;
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
Success #stdin #stdout 0.02s 25656KB
stdin
12 8
stdout
Array
(
    [0] => 1
    [1] => 2
    [3] => 4
)
4