๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm ๐Ÿง‘๐Ÿป‍๐Ÿ’ป/๋ฐฑ์ค€(BOJ)

[๋ฐฑ์ค€,c++] 1188๋ฒˆ - ์Œ์‹ ํ‰๋ก ๊ฐ€

by dkswnkk 2021. 11. 22.

๋ฌธ์ œ

 

1188๋ฒˆ: ์Œ์‹ ํ‰๋ก ๊ฐ€

์ฒซ์งธ ์ค„์— ์†Œ์‹œ์ง€์˜ ์ˆ˜ N๊ณผ ํ‰๋ก ๊ฐ€์˜ ์ˆ˜ M์ด ์ฃผ์–ด์ง„๋‹ค. (1 ≤ N, M ≤ 100)

www.acmicpc.net

 

์ฝ”๋“œ

#include <iostream>
#include <algorithm>
using namespace std;

int gcd(int a,int b){
    if(b==0) return a;
    else return gcd(b,a%b);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int a,b; cin>>a>>b;
    
    cout<<b-gcd(a,b);
}

๋Œ“๊ธ€