φ
(
p
)
=
a
1
k
1
∗
a
2
k
2
∗
.
.
.
.
.
.
.
.
∗
a
n
k
n
\varphi(p)=a_{1}^{k_{1}} * a_{2}^{k_{2}} * ........* a_{n}^{k_{n}}
φ(p)=a1k1∗a2k2∗........∗ankn
φ
(
a
i
k
i
)
=
(
a
i
k
i
−
a
i
k
i
)
=
a
i
k
i
−
1
∗
(
a
i
−
1
)
\varphi(a_{i}^{k_{i}})=(a_{i}^{k_{i}} - a_{i}^{k_{i}}) = a_{i}^{k_{i - 1}} * (a_{i} - 1)
φ(aiki)=(aiki−aiki)=aiki−1∗(ai−1)
φ
(
p
)
=
\varphi(p) =
φ(p)=
∏
i
=
1
n
\prod_{i = 1}^{n}
∏i=1n
φ
(
a
i
k
i
)
\varphi(a_{i}^{k_{i}})
φ(aiki)
=
∏
i
=
1
n
(
a
i
−
1
)
∗
a
i
k
i
−
1
\prod_{i = 1}^{n}(a_{i}-1) * a_{i}^{k_{i - 1}}
∏i=1n(ai−1)∗aiki−1
=
∏
i
=
1
n
\prod_{i = 1}^{n}
∏i=1n
(
1
−
1
a
i
)
∗
a
i
k
i
(1 - \frac{1}{a_{i}}) * a_{i}^{k_{i}}
(1−ai1)∗aiki
=
p
∗
p*
p∗
∏
i
=
1
n
\prod_{i = 1}^{n}
∏i=1n
(
1
−
1
a
i
)
(1 - \frac{1}{a_{i}})
(1−ai1)
所以如果遇到了偶数每次的
φ
(
p
)
\varphi(p)
φ(p)都会除2 遇到了奇数因为每次乘以
(
1
−
1
a
i
)
(1 - \frac{1}{a_{i}})
(1−ai1)所以下一次必定为偶数 所以只需要log次就可以变为1
那么对于这题来说
如果每次都是最后一种情况
b
c
b^{c}
bc =
b
c
m
o
d
(
φ
(
p
)
)
+
φ
(
p
)
m
o
d
p
b^{cmod(\varphi(p)) + \varphi(p)} mod p
bcmod(φ(p))+φ(p)modp
我们发现其实每次增加一层的话 Cmod 后面的欧拉函数就多一层 所以最后在logn次修改后就剩下 mod 1 + 1 = 1再根据题目的C不变最终就变为
c
c
c
c
c^{c^{^{c^{c} } } }
cccc 所以只要建立一颗线段树来存修改次数就行了
最后的复杂度就在大概 nlogn