hello

require "prime"

primes = []
Prime.each {|n| primes << n ; break if n > 4000 }
p primes.last

factors = Prime.prime_division(12_000)
p factors

prints

4001
[[2, 5], [3, 1], [5, 3]]

hope this helps

Ja xv wrote in post #1031499:
> question:
> How would you write the code to find the prime factors of a very large
> number?
>
> I think one of the factors is small (ie) less than 1000
> the code I have written is:
>
>
> print ' please enter num: '
> num_one=gets.chomp.to_i
> data = []
> for x in (3..1000)
>         if   x%2!=0 then
>              a = (x+1)/2
>                for i in (2..a)
>       if (x%i!=0)then
>         if i==a then
>           if num_one% x==x then
>             num_one/x=y
>             data <<x
>             print x
>             print y
>           end
>         end
>       end
>
>     end
>   end
> end
>
>
>
> #the large numbers given num_one and num_two are both odd
>
>
> num_one =
> 
21072236091611056689769183170665611839100660350189688162526899493835280729017620910006683962065747474746709582322870618924665901484145427690586656845288518421681715673619112289711701720430391346045498245691129378838117217972370441489717683798051804677941408786220581644893272649652708260725883926679251761833970410399147125916239687836131680486047711823435095777510281209932021075855270719904838238244264978537530033246226019262901302259332326201118956583817393649845723329843569413127263570255051462833626736607380988962342059574997647316022718247287419422282235170644994619557795227339530396253222625063056535813277
>
>
>
>
>
> num_2 =
> 
180980229898927614895852399429117101465275605765423295969005441424411086519047965226517527209287034243869824254236654269650778738505603896097810603554472797099957268999735645451862866599047554310106053073400016747052276933651693201994493045313861124048732077888820269415257040728350248748917830864512468597941793613527384250273032074597581295632021919688417670849218802439787068450273090792416213728427471241952690295098911214297345232764670796463979696711452531294829870748197355206752754348990795971540090615346527922888200122030125438669554525381727289927496029752456560988927002888169535698458197751522390933149786001
>
>
>
>
>
> ##I need help in writing the code, am I on the right track?

-- 
Posted via http://www.ruby-forum.com/.