fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int x, y;
  5.  
  6.  
  7.  
  8.  
  9. if (scanf("%d", &x) != 1 || x <= 0) {
  10.  
  11. return 1;
  12. }
  13.  
  14. if (scanf("%d", &y) != 1 || y <= 0) {
  15.  
  16. return 1;
  17. }
  18.  
  19.  
  20. while (x != y) {
  21. if (x > y) {
  22.  
  23. x = x - y;
  24. } else {
  25.  
  26. y = y - x;
  27. }
  28. }
  29.  
  30.  
  31. printf("最大公約数は %d です。\n", x);
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0s 5312KB
stdin
8
10
stdout
最大公約数は 2 です。