lib/primitive_root.rb
# Euler totient function denoted by phi(n)
# calculated using Euler product method
Euler totient function denoted by phi(n)
calculated using Euler product method
Euler totient function denoted by phi ( n ) calculated using Euler product method
def euler_totient(n)
		if Prime.prime?(n)
			n - 1
		else
			factors = distinct_factors(n).map{|f| (1 - (1.0/f.to_f))}
			return (n * factors.inject(:*)).to_i
		end
	end
def euler_totient ( n ) if Prime . prime? ( n ) n - 1 else factors = distinct_factors ( n ) . map { | f | ( 1 - ( 1.0 / f . to_f ) ) } return ( n * factors . inject ( :* ) ) . to_i end end
Euler totient function denoted by phi(n)
calculated using Euler product method
Euler totient function denoted by phi ( n ) calculated using Euler product method
n
<not_specific>