Project Euler 779

Project Euler 779

题目

Prime Factor and Exponent

For a positive integer $n>1$, let $p(n)$ be the smallest prime dividing $n$, and let $\alpha(n)$ be its $\mathbf{p}$-adic order, i.e. the largest integer such that $p(n)^{\alpha(n)}$ divides $n$.

For a positive integer $K$, define the function $f_K(n)$ by:

Also define $\overline{f_K}$ by:

It can be verified that $\overline{f_1} \approx 0.282419756159$.

Find $\displaystyle \sum_{K=1}^{\infty}\overline{f_K}$. Give your answer rounded to $12$ digits after the decimal point.

解决方案

将$\overline{f_K}$进行改写:

其中$P$表示一个质数集合。

假设$q$是一个质数。在所有正整数中,$p(n)=q$的比例如下(通过容斥原理不难写出):

那么,在质数$q$的倍数$n$中,有$\dfrac{q-1}{q}$的数满足$\alpha(n)=1$,有$\dfrac{1}{q}\cdot \dfrac{q-1}{q}$的数满足$\alpha(n)=2$……有$\dfrac{q-1}{q^e}$的数满足$\alpha(n)=e$。因此,$\overline{f_K}$可以进一步改写成:

由于$\displaystyle{\sum_{e=1}^{\infty} \dfrac{e-1}{q^e}=\dfrac{1}{(q-1)^2}}$,因此整个式子可以化简成

那么根据等比数列公式,有$\displaystyle{\sum_{K=1}^{\infty} \dfrac{1}{q^K}=\dfrac{1}{q-1}}$

那么最终化简后,得到

直接枚举质数$q$,边枚举质数$q$,边计算第二项求积式,直到级数中某一项的值小于$10^{-16}$时停止计算。

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from sympy import nextprime

N = 12
eps = 10 ** -(N + 4)
mul = 1
ans = 0
p = 1
while True:
p = nextprime(p)
r = mul / p / (p - 1) ** 2
if r < eps:
break
ans += r
mul *= (p - 1) / p
ans = round(ans, N)
print(ans)