https://www.acmicpc.net/problem/1850
[난이도] Silver1
[유형] 수학
[풀이]
1의 개수끼리 최대 공약수를 구한 뒤,
이 수만큼 1을 출력해주면 정답이라고 합니다.
증명은 못하겠어서 gcd 구하는 연습용으로 풀었습니다..
#include <cstdio>
#include <algorithm>
using namespace std;
using ll = long long;
ll a,b;
ll gcd(ll a,ll b){
if(b>a) swap(a,b);
while(b!=0){
ll c = a%b;
a=b;
b=c;
}
return a;
}
int main(){
scanf("%lld%lld",&a,&b);
for(int i=0;i<gcd(a,b);i++) printf("1");
}
https://github.com/has2/Problem-Solving/blob/master/boj-solved.ac/Silver1/1850.cpp
'Problem-Solving > BOJ' 카테고리의 다른 글
[BOJ/백준][Silver1] 2343 : 기타 레슨 (C++) (0) | 2022.09.26 |
---|---|
[BOJ/백준][Gold5] 2866 : 문자열 잘라내기 (C++) (0) | 2022.09.26 |
[BOJ/백준][Silver1] 2504 : 괄호의 값 (C++) (0) | 2022.09.26 |
[BOJ/백준][Silver1] 1926 : 그림 (C++) (0) | 2022.09.26 |
[BOJ/백준][Gold5] 21608 : 상어 초등학교 (C++) (0) | 2022.09.26 |