728x90
4375 1
https://www.acmicpc.net/problem/4375
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
unsigned int num;
int i = 0;
while (cin >> num)
{
int check = 1;
i = 1;
while (1)
{
if (0 == check % num)
break;
else
{
++i;
check = check * 10 + 1;
check %= num;
}
}
cout << i << endl;
}
return 0;
}
- 1,11,111,1111,1111 … 로 커져나가면서 num으로 나누어떨어지는지 확인하는 문제
- 계속 숫자를 키워나갔더니 idx초과 문제가 떴다.
- 그래서 modular연산을 통해서 값을 넘겨주는 방식을 사용했다.
728x90
'Study > Baekjoon' 카테고리의 다른 글
[백준/C++] 1107 리모컨 (0) | 2024.04.21 |
---|---|
[백준/C++] 1406 에디터 (1) | 2024.04.12 |
[백준/C++] 11728 배열 합치기 (0) | 2024.04.08 |
[백준/C++] 1269 대칭 차집합 (0) | 2024.04.06 |
[백준/C++] 14502 연구소 (0) | 2024.04.01 |