본문 바로가기

백준 문제풀이/Bruteforcing

[C++] 백준 문제풀이 (Bruteforcing) 4375번 1

 

 

 

 

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

 

4375번: 1

2와 5로 나누어 떨어지지 않는 정수 n(1 ≤ n ≤ 10000)가 주어졌을 때, 각 자릿수가 모두 1로만 이루어진 n의 배수를 찾는 프로그램을 작성하시오.

www.acmicpc.net

 

 

//[C++] 백준 문제풀이 (Bruteforcing)

#include <bits/stdc++.h>


int main(){
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n;
    while(std::cin >> n){
        long long num = 1;
        int cnt = 1;
        while(true){
            if (num % n == 0) break;
            num = num * 10 + 1;
            num %= n;
            ++cnt;
        }
        std::cout << cnt << "\n";
    }
    return 0;
}