# 생각
1로 이루어진 수는 1 * 10 + 1로 표현할 수 있다
나머지연산은 (a * b) % c = a % c * b % c 성질이 있다
위를 이용하면 해결 가능하다
# 전체 코드
#include <bits/stdc++.h>
using namespace std;
void fastIO() { ios::sync_with_stdio(false); cin.tie(nullptr); }
int main()
{
fastIO();
int n;
while (cin >> n)
{
int cnt = 1, ans = 1;
while (true)
{
if (cnt % n == 0)
{
cout << ans << '\n';
break;
}
else
{
cnt = cnt * 10 + 1;
cnt %= n;
ans++;
}
}
}
}
https://www.acmicpc.net/problem/4375
4375번: 1
2와 5로 나누어 떨어지지 않는 정수 n(1 ≤ n ≤ 10000)가 주어졌을 때, 1로만 이루어진 n의 배수를 찾는 프로그램을 작성하시오.
www.acmicpc.net
'Algorithm > BOJ' 카테고리의 다른 글
[BOJ] 2178_미로 탐색.cpp (0) | 2022.05.31 |
---|---|
[BOJ] 1629_곱셈.cpp (0) | 2022.05.30 |
[BOJ] 3986_좋은 단어.cpp (0) | 2022.05.30 |
[BOJ] 1940_주몽.cpp (0) | 2022.05.30 |
[BOJ] 1213_팰린드롬 만들기.cpp (0) | 2022.05.30 |