본문 바로가기
알고리즘 & 자료구조/백준

백준 4375

by 신재권 2021. 12. 15.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main4375 {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		while(true) {
			String s = br.readLine();
			if(s == null) {
				break;
			}
			int N = Integer.parseInt(s);
			int num = 0;
			for(int i=1; i<=N; i++) {
				num = num*10 + 1;  // 자리수를 늘려준다.
				num %= N;                     
				//((3*3+2) * 10 +1)%3 == ((3+2)*10+1)%3 
				if(num == 0) { //나머지가 0이면 나누어 떨어진다 
					System.out.println(i);
					break;
				}
			}
			
		}
		
	}

}

'알고리즘 & 자료구조 > 백준' 카테고리의 다른 글

백준 2012  (0) 2021.12.17
백준 6236  (0) 2021.12.16
백준 10211  (0) 2021.12.14
백준 2615  (0) 2021.12.13
백준 1269  (0) 2021.12.12