Advertisement
jukaukor

Gausstotientit.jl

Apr 4th, 2021
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. # totientit 1...n using Gauss divisor sum property
  2. # idea https://cp-algorithms.com/algebra/phi-function.html
  3. # Juhani Kaukoranta 4.4.2021
  4. # Julia-ohjelma Gausstotientit.jl
  5. function Gausstotientit(n)
  6. phi =Vector{Int64}(undef,n)
  7. phi[1]=1
  8. phi[2]=1
  9. for i = 2:n
  10. phi[i] = i-1
  11. end
  12. for i = 2:n
  13. for j = 2*i : i : n
  14. phi[j] -= phi[i]
  15. end
  16. end
  17. return phi
  18. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement