본문 바로가기
Algorithm/BaekJoon[Java]

백준 1850

by 씨니 2022. 3. 31.
728x90

▶ 1850번 문제 - 최대공약수

 

▶ 풀이방법

++ 9613번 문제와 비슷( https://shinny.tistory.com/154 )

import java.util.*;
import java.io.*;
public class Main {
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		
		StringTokenizer st = new StringTokenizer(br.readLine());
		long a = Long.parseLong(st.nextToken());
		long b = Long.parseLong(st.nextToken());
		
		long num = gcd(a,b);
		
		for(int i = 0; i < num; i++) {
			bw.write("1");
		}
		
		bw.flush();
		bw.close();
		br.close();
	}

	private static long gcd(long a, long b) {
		if(b == 0) return a;
		return gcd(b, a%b);
	}
}
728x90

'Algorithm > BaekJoon[Java]' 카테고리의 다른 글

백준 2745  (0) 2022.03.31
백준 11005  (0) 2022.03.31
백준 9613  (0) 2022.03.30
백준 1934  (0) 2022.03.30
백준 2609  (0) 2022.03.30