luogu#P4884. 多少个 1?

    ID: 3876 远端评测题 2000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>素数判断,质数,筛法进制洛谷月赛大步小步算法 BSGS

多少个 1?

Problem Description

Given an integer KK and a prime number mm, find the smallest positive integer NN such that 11111\cdots1 (NN digits of 11) K(modm)\equiv K \pmod m.

In plain words: 1111111modm=K111\cdots 1111 \bmod m = K.

Input Format

The first line contains two integers, representing KK and mm.

Output Format

Output one integer, the smallest NN that satisfies the condition.

9 17
3

Hint

For 30%30\% of the testdata, m106m \leq 10^6.

For 60%60\% of the testdata, m5×107m \leq 5 \times 10^7.

For 100%100\% of the testdata, 6m10116 \leq m \leq 10^{11}, 0<K<m0 < K < m, and mm is guaranteed to be prime.

Translated by ChatGPT 5