https://www.acmicpc.net/problem/4375
4375번: 1
2와 5로 나누어 떨어지지 않는 정수 n(1 ≤ n ≤ 10000)가 주어졌을 때, 1로만 이루어진 n의 배수를 찾는 프로그램을 작성하시오.
www.acmicpc.net
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
while(cin>>n){
long long ans=1;
long long num=1;
while(1){
long long temp=num;
if(temp%n==0) break;
num=(num*10)+1;
num%=n; //modular 연산 통해 정수 오버플로우 방지
ans++;
}
cout<<ans<<"\n";
}
return 0;
}
'ALG > ALG Solve' 카테고리의 다른 글
[C++] 백준 1789번 - 수들의 합 (0) | 2023.07.14 |
---|---|
[C++] 백준 5585번 - 거스름돈 (0) | 2023.07.14 |
C++) 백준 18870번 - 좌표 압축 (0) | 2023.02.21 |
C++) 백준 2170번 - 선 긋기 (0) | 2023.02.14 |
C++) 백준 1541번 - 잃어버린 괄호 (0) | 2023.02.14 |