#include <stdio.h>

int main() {
    int a, b;
    scanf("%d%d", &a, &b);
    int R;

    while (b != 0) { /* 어차피 b가 0이 아닐때만 돌아감, b가 0이면 나눌 수 없으므로,
    자동으로 최대공약수가 a가 됨
    b(즉, 나누는 수)가 0이 아니면, 프로그램은 항상 돌아가며, b가 0이 되는 순간 while문은
    멈추고, b가 0이 되기 직전 값이 저장되어 있는 a의 값을 출력하고, 그것이 최대공약수임 */
        R = a % b;
        a = b;
        b = R;
    }
    printf("%d", a);
    return 0;
}
    // while (1) {
    //      R = a % b;
    //      if (R == 0) {
    //          printf("%d", b);
    //          break;
    //      }
    //      else if (b != 0) {
    //          a = b;
    //          b = R;
    //          printf("%d", b);
    //      }
    //  }

//     while (b != 0) {
//         R = a % b;
//         a = b;
//         b = R;
//     }
//     printf("%d", a);

//     if (R == 0) {
//         printf("%d", b);
//     }
//     return 0;
// }
    
//     while (1) {
//         R = a % b;
//         if (R == 0) {
//             break;
//         }
//         else {
//             a = b;
//             b = R;
//         }
//     printf("%d", b);
//     }
//         return 0;
// }
    
    /* 
    int a, b;
    scanf("%d%d", &a, &b);
    int R;
    
    while (R != 0) {
        R = a % b;
        a = b;
        b = R;
    }
    printf("%d", b);

    if (R == 0) {
        printf("%b", b);
    } */
    
    /* while (1) {
        if (R == 0) {
            break;
        }
        else {
            R = a % b;
            a = b;
            b = R;
        }
        printf("%d", b)
    } */


/* 파이썬
a = input()
b = input()

while True:
    R = a % b
    if (R == 0):
        break
    else:
        a = b
        b = R

print(b) */

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: