0%

Problem 69


Problem 69


Totient Maximum

Euler’s Totient function, φ(n) [sometimes called the phi function], is used to determine the number of numbers less than n which are relatively prime to n. For example, as 1, 2, 4, 5, 7, and 8, are all less than nine and relatively prime to nine, φ(9)=6.

n Relatively Prime φ(n) n/φ(n)
2 1 1 2
3 1,2 2 1.5
4 1,3 2 2
5 1,2,3,4 4 1.25
6 1,5 2 3
7 1,2,3,4,5,6 6 1.1666
8 1,3,5,7 4 2
9 1,2,4,5,7,8 6 1.5
10 1,3,7,9 4 2.5

It can be seen that n=6 produces a maximum n/φ(n) for n10.

Find the value of n1,000,000 for which n/φ(n) is a maximum.


欧拉总计函数与最大值

小于n且与n互质的正整数的数量记为欧拉总计函数φ(n)。例如,124578均小于9且与9互质,因此φ(9)=6

n 互质的数 φ(n) n/φ(n)
2 1 1 2
3 1,2 2 1.5
4 1,3 2 2
5 1,2,3,4 4 1.25
6 1,5 2 3
7 1,2,3,4,5,6 6 1.1666
8 1,3,5,7 4 2
9 1,2,4,5,7,8 6 1.5
10 1,3,7,9 4 2.5

可以看出,对于n10,当n=6n/φ(n)取得最大值。

对于n1,000,000,求使得n/φ(n)取得最大值的n


1 comment
Anonymous
Markdown is supported
@shangkelingxiang
shangkelingxiangcommentedabout 3 years ago
pri=[]
v=[0]*1000001
phi=[0]*1000001
v[0]=v[1]=1
phi[1]=1
for i in range(2,1000001):
  if not v[i]:
    pri.append(i)
    phi[i]=i-1
  for j in pri:
    if i*j>=1000001:
      break
    v[i*j]=1
    if i%j==0:
      phi[i*j]=phi[i]*j
      break
    phi[i*j]=phi[i]*phi[j]
ans,t=0,0
for i in range(1,1000001):
  if i/phi[i]>t:
    ans,t=i,i/phi[i]
print(ans)