본문 바로가기

Programming/BaekJoon

[C++] 백준 1188번 : 음식 평론가


https://www.acmicpc.net/problem/1188




#include<iostream>

using namespace std;

int main() {

int n, m;

cin >> n >> m;

int cnt = 0;


while (1) {

if ((n = n % m) == 0)

break;


if (m%n == 0)

{

cnt = (m / n - 1)*n + cnt;

break;

}

else {

cnt = (m / n)*n + cnt;

m = m % n;

}

}


cout << cnt << endl;

}