๐Ÿ•๏ธ ICPC Sinchon/Basic Math

[BOJ S5][C++] ๋ฐฑ์ค€ 14490๋ฒˆ: ๋ฐฑ๋Œ€์—ด

์„ ๋‹ฌ 2022. 9. 19. 03:21
๋ฐ˜์‘ํ˜•

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

 

14490๋ฒˆ: ๋ฐฑ๋Œ€์—ด

n๊ณผ m์ด :์„ ์‚ฌ์ด์— ๋‘๊ณ  ์ฃผ์–ด์ง„๋‹ค. (1 ≤ n, m ≤ 100,000,000)

www.acmicpc.net

 

๋ฌธ์ œ

๋Œ€์—ด์ด๋Š” ์šฑ์ œ์˜ ์นœ๊ตฌ๋‹ค.

  • “์•ผ ๋ฐฑ๋Œ€์—ด์„ ์•ฝ๋ถ„ํ•˜๋ฉด ๋ญ”์ง€ ์•Œ์•„?”
  • “??”
  • “์‹ญ๋Œ€์ผ์ด์•ผ~ ํ•˜ํ•˜!”

n:m์ด ์ฃผ์–ด์ง„๋‹ค. ์šฑ์ œ๋ฅผ ๋„์™€์ฃผ์ž. (...)

์ž…๋ ฅ

n๊ณผ m์ด :์„ ์‚ฌ์ด์— ๋‘๊ณ  ์ฃผ์–ด์ง„๋‹ค. (1 ≤ n, m ≤ 100,000,000)

์ถœ๋ ฅ

๋‘ ์ˆ˜๋ฅผ ์ตœ๋Œ€ํ•œ์œผ๋กœ ์•ฝ๋ถ„ํ•˜์—ฌ ์ถœ๋ ฅํ•œ๋‹ค.

 

ํ’€์ด

์œ ํด๋ฆฌ๋“œ ํ˜ธ์ œ๋ฒ•์„ ์ด์šฉํ•œ๋‹ค

[๐ŸŒฒ Altu-Bitu/0913 ์ •์ˆ˜๋ก ] - [BOJ][C++] ๋ฐฑ์ค€ 2609๋ฒˆ : ์ตœ๋Œ€๊ณต์•ฝ์ˆ˜์™€ ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜

// Authored by : seondal
// Co-authored by : -

// #include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>

using namespace std;

int getGcd(int n, int m) {
    if(m == 0) return n;
    return getGcd(m, n%m);
}

int main() {
    int n, m;
    scanf("%d:%d", &n, &m);
    
    int gcd = getGcd(n, m);
    
    cout << n/gcd << ":" << m/gcd;
    
    return 0;
}

/*
 */

 

๋ฐ˜์‘ํ˜•