php 实现欧拉函数Euler
发布时间:2020-12-13 21:22:25 所属栏目:PHP教程 来源:网络整理
导读:欧拉函数ph(n)的意思是所有小于n且与n互质的个数。 比如说ph(10) = 4{1,3,7,9与10互质} 代码如下: ? 1 function Euler( $x ) 2 { 3 $res = ; 4 $now = 2 5 while ( $x 1 ) { 6 if ( $x % $now == 0 7 $res /= $now 8 $res *= ( $now - 1 ); 9 10 $x /= 11 }
欧拉函数ph(n)的意思是所有小于n且与n互质的个数。
? 1 function Euler($x) 2 { 3 $res = ; 4 $now = 2 5 while ($x > 1) { 6 if ($x % $now == 0 7 $res /= $now 8 $res *= ($now - 1); 9 10 $x /= 11 } 12 } 13 $now++14 } 15 return $res16 } 17 18 $res = Euler(1019 20 var_dump($res); ? ? function Euler($x) $res = Euler(10); var_dump($res); ? done! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |