module AtCoder::Prime
Overview
Implements Ruby's Prime library.
AtCoder::Prime.first(7) # => [2, 3, 5, 7, 11, 13, 17]
Included Modules
- Enumerable(Int64)
Extended Modules
Defined in:
prime.crInstance Method Summary
-
#each(&)
Must yield this collection's elements to the block.
-
#each_divisor(value : Int)
Returns an enumerator that iterates through the all positive divisors of the given number.
-
#each_divisor(value : T, &block : T -> )
Returns an enumerator that iterates through the all positive divisors of the given number.
- #int_from_prime_division(prime_divisions : Array(Tuple(Int, Int)))
- #prime?(value : Int)
- #prime_division(value : Int)
Instance Method Detail
def each(&)
#
Description copied from module Enumerable(Int64)
Must yield this collection's elements to the block.
Returns an enumerator that iterates through the all positive divisors of the given number. The order is not guaranteed. Not in the original Ruby's Prime library.
AtCoder::Prime.each_divisor(20) do |n|
puts n
end # => Puts 1, 2, 4, 5, 10, and 20
AtCoder::Prime.each_divisor(10).map { |n| 1.0 / n }.to_a # => [1.0, 0.5, 0.2, 0.1]
def each_divisor(value : T, &block : T -> )
#
Returns an enumerator that iterates through the all positive divisors of the given number. The order is not guaranteed. Not in the original Ruby's Prime library.
AtCoder::Prime.each_divisor(20) do |n|
puts n
end # => Puts 1, 2, 4, 5, 10, and 20
AtCoder::Prime.each_divisor(10).map { |n| 1.0 / n }.to_a # => [1.0, 0.5, 0.2, 0.1]