tag:blogger.com,1999:blog-8712770457197348465.post8958963679486867517..comments2024-03-28T02:47:19.159-07:00Comments on Javarevisited: How to generate Prime numbers in Java? Sieve of Eratosthenes Algorithm Examplejavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-8712770457197348465.post-44013158712732122472015-05-26T21:04:25.762-07:002015-05-26T21:04:25.762-07:00This is how you do it with SCALA
object Numbers e...This is how you do it with SCALA<br /><br />object Numbers extends App {<br /><br /> /**<br /> * Stream of Int starting with "n"<br /> * @param n<br /> * @return<br /> */<br /> def from(n:Int): Stream[Int] = {<br /> n #:: from(n+1)<br /> }<br /><br /> /**<br /> * All natural numbers<br /> */<br /> var naturals = from(0)<br /><br /> /**<br /> * Stream of Prime Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-18080643341372885852015-05-26T20:02:08.781-07:002015-05-26T20:02:08.781-07:00Once I had to find prime divisors of a number. I a...Once I had to find prime divisors of a number. I also used sieve of Eratosthenes to get all prime numbers in range and then check wich one of them is a divisor on my number. But then my teacher showed me very simple and extremely fast algorithm. This method is not about finding all prime numbers but for example if I'll try to do this using your algorithm I'll get OutOfMemoryError: Java Максhttps://www.blogger.com/profile/14622842319701951971noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-30592229384636966292015-05-26T08:41:54.911-07:002015-05-26T08:41:54.911-07:00A much more interesting problem to solve with this...A much more interesting problem to solve with this algorithm would be: find the first N prime numbers, rather than finding all prime numbers up to N.Anonymousnoreply@blogger.com