[ 백준 ] 4375 / 1

金弘均·2021년 9월 15일
0

Baekjoon Online Judge

목록 보기
63/228
post-thumbnail

# Appreciation

/*
 * Problem :: 4375 / 1
 *
 * Kind :: Brute Force
 *
 * Insight
 * - x%n = v
 *   (10*x+1)%n = (10*v+1)%n
 *
 * - 2와 5로 나누어 떨어지지 않는 정수 n 은
 *   1로만 이루어진 n의 배수를 가진다
 *   + val :  1, 11, 111, ..., 11...11
 *     len :  1,  2,   3, ...,     N+1
 *     res : a1, a2,  a3, ...,     a_(N+1)
 *     # 1~(N+1)개의 res 중 N 으로 나누었을 때
 *       나머지가 같은 두 수가 무조건 존재한다
 */

# Code

//
//  Codeforces
//  ver.C++
//
//  Created by GGlifer
//
//  Open Source

#include <iostream>

using namespace std;

#define endl '\n'

// Set up : Global Variables
/* None */

// Set up : Functions Declaration
/* None */


int main()
{
    // Set up : I/O
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    // Set up : Input
    int N;
    while (cin >> N) {

        // Process
        int len = 1, res = 1 % N;
        while (res != 0) {
            res *= 10;
            res += 1;
            res %= N;
            len++;
        }

        // Control : Output
        cout << len << endl;
    }
}

// Helper Functions
/* None */
profile
이런 미친 게임을 봤나! - 옥냥이

0개의 댓글