Solution
Suppose the problem is solvable and let the answer be x x x, then 888... % L = 0 888... \% L = 0 888...%L=0
888... ≡ 0 ( % L ) 888... \equiv 0 (\% L) 888...≡0(%L)
8 ∗ 1 0 x − 1 9 = k ∗ L 8 * \frac{10^x - 1}{9} = k * L 8∗910x−1=k∗L (where k k k is unknown, it is a certain integer k > 0 k > 0 k>0 due to x > 0 x >0 x>0)
1
0
x
−
1
=
k
∗
9
∗
L
8
10^x - 1 = \frac{k * 9 * L}{8}
10x−1=8k∗9∗L (Note that, the right hand fraction must be a integer
>
0
> 0
>0 due to
k
>
0
k > 0
k>0, and
k
∗
9
∗
L
8
≠
k
∗
9
∗
L
8
\frac{k * 9 * L}{8} \neq k * \frac{9 * L}{8}
8k∗9∗L=k∗89∗L according to 整数分式的分解)
.
Cuz
k
k
k is unknown, we should take it out of the formula; Let
g
=
G
C
D
(
9
∗
L
,
8
)
g = GCD(9*L, 8)
g=GCD(9∗L,8) and
8
=
g
∗
t
8 = g * t
8=g∗t, then
k
∗
9
∗
L
8
=
k
t
∗
9
∗
L
g
\frac{k * 9 * L}{8} = \frac{k}{t} * \frac{9 * L}{g}
8k∗9∗L=tk∗g9∗L where the right-hand two fraction must be integer; now let
k
1
=
k
t
k_1 = \frac{k}{t}
k1=tk be the unknown.
1 0 x − 1 = k 1 ∗ 9 ∗ L g 10^x - 1 = k_1 * \frac{9 * L}{g} 10x−1=k1∗g9∗L ( k 1 k_1 k1 is a certain integer)
1 0 x − 1 ≡ 0 ( % 9 ∗ L g ) 10^x - 1 \equiv 0 (\% \frac{9 * L}{g}) 10x−1≡0(%g9∗L) (According to 将等式转换为同余式)
Finally, 1 0 x ≡ 1 ( % 9 ∗ L g ) 10^x \equiv 1 (\% \frac{9 * L}{g}) 10x≡1(%g9∗L)
For generality,
a
x
≡
1
(
%
M
)
a^x \equiv 1 (\% M)
ax≡1(%M)
+
Solvable if-and-only-if
a
,
M
a,M
a,M are co-prime;
+
According to 最小正幂为欧拉函数的约数, iterating all divisors of
x
∣
ϕ
(
M
)
x | \phi(M)
x∣ϕ(M), and using Binary-Exponentiation to test whether
a
x
%
M
a^x \% M
ax%M equals
1
1
1;
Code
L;
M = 9 * L / GCD(9 * L, 8);
if( GCD( M, 10) != 1){
return "Unsolvable";
}
Phi = $( euler_function of `M`);
for( `x` : all divisors of `Phi` increasingly){
if( $10 ^ x (% M)$ == 1){
return "answer is x";
}
}