Calculating phi(k) for 1<k<N

前端 未结 9 1829
花落未央
花落未央 2020-12-04 20:08

Given a large N, I need to iterate through all phi(k) such that 1 < k < N :

  • time-complexity must be O(N logN)
  • memory-complexity mus
9条回答
  •  一整个雨季
    2020-12-04 20:58

    No one has found a faster way to calculate phi(k) (aka, Euler's totient function) than by first finding the prime factors of k. The world's best mathematicians have thrown many CPU cycles at the problem since 1977, since finding a faster way to solve this problem would create a weakness in the RSA public-key algorithm. (Both the public and the private key in RSA are calculated based on phi(n), where n is the product of two large primes.)

提交回复
热议问题