백준 algorithm

백준 1850 - 최대공약수

cosmohoo 2020. 3. 10. 01:19
반응형

문제 설명 

 

 

=>실제로 입력받은 갯수로 1로 이루어진 숫자로 최대 공약수를 만들면 안된다. 

=>입력 받은 값의 최대 공약수를 구한 다음 그 값을 limit으로 1을 출력하면 된다. 

 

 

#include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int gcd(long long a, long long b)
{
    long long c;
    while (b != 0)
    {
        c = a % b;
        a = b;
        b = c;
    }
    return a;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    long long A,B;
    cin>>A>>B;
    
    int limit=gcd(A,B);
    
    for(int i=0; i<limit; ++i)
    {
        cout<<1;
    }
    cout<<'\n';
    return 0;
}

반응형