Last active
May 12, 2019 05:02
-
-
Save yamasushi/873992c10d8ac74750f3fa9d3ec039f4 to your computer and use it in GitHub Desktop.
(オイラーの)totient関数の性質
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://gist.github.com/yamasushi/873992c10d8ac74750f3fa9d3ec039f4 | |
| # https://qiita.com/yamasushi/items/fc0d4c77d26bb5d05ed3 | |
| using DataFrames | |
| using Primes | |
| n=30 | |
| @show(n) | |
| gcds = gcd.(n,1:n) | |
| df=DataFrame( | |
| i = 1:n | |
| , gcd_n_i = gcds | |
| , div_n_gcd= div.(n ,gcds) | |
| , div_i_gcd= div.(1:n,gcds) | |
| ) | |
| sort!(df,:div_n_gcd) | |
| gcd_n_i =unique(df.gcd_n_i) | |
| div_n_gcd =unique(df.div_n_gcd) | |
| z_zms = | |
| map(div_n_gcd) do m | |
| m , | |
| rename(df[ df.div_n_gcd .== m , [:i,:div_i_gcd]] , | |
| :div_i_gcd=>Symbol("(Z/Z$m)×")) | |
| end | |
| totient_gcd_n_i =totient.(gcd_n_i) | |
| totient_div_n_gcd=totient.(div_n_gcd) | |
| println("(n,i)=$gcd_n_i , totients=$totient_gcd_n_i , sum=$(sum(totient_gcd_n_i))") | |
| println("n/(n,i)=$div_n_gcd , totients=$totient_div_n_gcd , sum=$(sum(totient_div_n_gcd))") | |
| rename!(df, | |
| :gcd_n_i =>Symbol("(n,i)") , | |
| :div_n_gcd=>Symbol("n/(n,i)") , | |
| :div_i_gcd=>Symbol("i/(n,i)")) | |
| println("") | |
| show(df) | |
| println("\n") | |
| for (m,z_zm) in z_zms | |
| #@show(z_zm) | |
| println("m=$m , totient=$(totient(m))") | |
| show(z_zm) | |
| println("\n") | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment