개발/알고리즘

백준 4375 1 C++

daisy-day 2021. 5. 15. 01:59

문제

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;
typedef long long ll;

int main()
{
	ll n = 0.0;
	while (cin >> n)
	{
		ll m = 1.0;
		int digits = 1;
		while ((m % n) != 0)
		{
			m %= n;
			m = m * 10 + 1;
			//m = (m * 10) % n + 1;
			digits++;
		}
		cout << digits << "\n";
	}

	return 0;
}

참고한 블로그

https://unfunhy.tistory.com/m/36