Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
14
Task/Totient-function/Ruby/totient-function.rb
Normal file
14
Task/Totient-function/Ruby/totient-function.rb
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
require "prime"
|
||||
|
||||
def 𝜑(n)
|
||||
n.prime_division.inject(1) {|res, (pr, exp)| res *= (pr-1) * pr**(exp-1) }
|
||||
end
|
||||
|
||||
1.upto 25 do |n|
|
||||
tot = 𝜑(n)
|
||||
puts "#{n}\t #{tot}\t #{"prime" if n-tot==1}"
|
||||
end
|
||||
|
||||
[100, 1_000, 10_000, 100_000].each do |u|
|
||||
puts "Number of primes up to #{u}: #{(1..u).count{|n| n-𝜑(n) == 1} }"
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue