Skip to content

Instantly share code, notes, and snippets.

@t-murano
Created December 31, 2013 05:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t-murano/8193170 to your computer and use it in GitHub Desktop.
Save t-murano/8193170 to your computer and use it in GitHub Desktop.
Rubyによる素因数分解と、分解された数から元の数字を生成する方法
require 'prime'
factors = 242.prime_division
# もしくは factors = Prime.prime_division(242)
p factors #=> [[2, 1], [11, 2]]
composite_num = Prime.int_from_prime_division([[2, 1], [3, 1], [11, 2]])
p composite_num #=> 726
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment