Hey everyone....
I would appreciate any type of help if anyone could explain me how to
translate this algorithm to Visual Basic, im still learning and i
would appreciate this algorithm to my prime number program, which
lists primes but can use different algorithms.
// arbitrary search limit
limit ← 1.000.000
// assume all numbers are prime at first
is_prime(i) ← true, i ∈ [2, limit]
for n in [2, √limit]:
if is_prime(n):
// eliminate multiples of each prime,
// starting with its square
is_prime(i) ← false, i ∈ {n², n²+n, n²+2n, ..., limit}
for n in [2, limit]:
if is_prime(n): print n
this is listed in wikipedia, and there is also another form which i
find even more complicated. but i dont understand how can i eliminate
multiples and all of the rest, if anyone could point me to an easy
explanation.
Thanks in advance... 4 3379
On Apr 10, 10:05 am, "knu...@gmail.com" <knu...@gmail.comwrote:
Hey everyone....
I would appreciate any type of help if anyone could explain me how to
translate this algorithm to Visual Basic, im still learning and i
would appreciate this algorithm to my prime number program, which
lists primes but can use different algorithms.
// arbitrary search limit
limit ← 1.000.000
// assume all numbers are prime at first
is_prime(i) ← true, i ∈ [2, limit]
for n in [2, √limit]:
if is_prime(n):
// eliminate multiples of each prime,
// starting with its square
is_prime(i) ← false, i ∈ {n², n²+n, n²+2n, ..., limit}
for n in [2, limit]:
if is_prime(n): print n
this is listed in wikipedia, and there is also another form which i
find even more complicated. but i dont understand how can i eliminate
multiples and all of the rest, if anyone could point me to an easy
explanation.
Thanks in advance...
http://www.physicsforums.com/showthread.php?t=9298
Let me know if that thread doesn't answer your question and I'll take
another look.
Thanks,
Seth Rowe
On Apr 10, 3:46 pm, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
On Apr 10, 10:05 am, "knu...@gmail.com" <knu...@gmail.comwrote:
Hey everyone....
I would appreciate any type of help if anyone could explain me how to
translate this algorithm to Visual Basic, im still learning and i
would appreciate this algorithm to my prime number program, which
lists primes but can use different algorithms.
// arbitrary search limit
limit ← 1.000.000
// assume all numbers are prime at first
is_prime(i) ← true, i ∈ [2, limit]
for n in [2, √limit]:
if is_prime(n):
// eliminate multiples of each prime,
// starting with its square
is_prime(i) ← false, i ∈ {n², n²+n, n²+2n, ..., limit}
for n in [2, limit]:
if is_prime(n): print n
this is listed in wikipedia, and there is also another form which i
find even more complicated. but i dont understand how can i eliminate
multiples and all of the rest, if anyone could point me to an easy
explanation.
Thanks in advance...
http://www.physicsforums.com/showthread.php?t=9298
Let me know if that thread doesn't answer your question and I'll take
another look.
Thanks,
Seth Rowe
If anyone else could give another hint, all things that are said in
that forum are kinda advanced to me..its all about datasets and
statusbars...i just wantend something to print prime numbers in a
textbox, using the sieve of eratosthenes...
thanks
On Apr 10, 12:57 pm, "knu...@gmail.com" <knu...@gmail.comwrote:
On Apr 10, 3:46 pm, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
On Apr 10, 10:05 am, "knu...@gmail.com" <knu...@gmail.comwrote:
Hey everyone....
I would appreciate any type of help if anyone could explain me how to
translate this algorithm to Visual Basic, im still learning and i
would appreciate this algorithm to my prime number program, which
lists primes but can use different algorithms.
// arbitrary search limit
limit ← 1.000.000
// assume all numbers are prime at first
is_prime(i) ← true, i ∈ [2, limit]
for n in [2, √limit]:
if is_prime(n):
// eliminate multiples of each prime,
// starting with its square
is_prime(i) ← false, i ∈ {n², n²+n,n²+2n, ..., limit}
for n in [2, limit]:
if is_prime(n): print n
this is listed in wikipedia, and there is also another form which i
find even more complicated. but i dont understand how can i eliminate
multiples and all of the rest, if anyone could point me to an easy
explanation.
Thanks in advance...
http://www.physicsforums.com/showthread.php?t=9298
Let me know if that thread doesn't answer your question and I'll take
another look.
Thanks,
Seth Rowe
If anyone else could give another hint, all things that are said in
that forum are kinda advanced to me..its all about datasets and
statusbars...i just wantend something to print prime numbers in a
textbox, using the sieve of eratosthenes...
thanks
Here's another article - I believe it uses the Sieve of Eratosthenes: http://www.codeproject.com/cs/algori...imenumbers.asp
I also took the liberty of translating the code into VB for you - I
didn't test the algorithm completely though so be careful:
Sub Main()
' Change this for a different cutoff
Dim topNumber As Integer = 1000000
Dim numbers As BitArray = New BitArray(topNumber, True)
For i As Integer = 2 To topNumber - 1
If numbers(i) Then
For j As Integer = i * 2 To topNumber - 1 Step i
numbers(j) = False
Next
End If
Next
Dim primes As Integer = 0
For i As Integer = 1 To topNumber - 1
If numbers(i) Then
primes += 1
' Console.WriteLine(i.ToString())
End If
Next
Console.WriteLine()
Console.WriteLine("{0} out of {1} prime numbers found.",
primes, topNumber)
Console.Read()
End Sub
Thanks,
Seth Rowe
On Apr 10, 6:47 pm, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
On Apr 10, 12:57 pm, "knu...@gmail.com" <knu...@gmail.comwrote:
On Apr 10, 3:46 pm, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
On Apr 10, 10:05 am, "knu...@gmail.com" <knu...@gmail.comwrote:
Hey everyone....
I would appreciate any type of help if anyone could explain me how to
translate this algorithm to Visual Basic, im still learning and i
would appreciate this algorithm to my prime number program, which
lists primes but can use different algorithms.
// arbitrary search limit
limit ← 1.000.000
// assume all numbers are prime at first
is_prime(i) ← true, i ∈ [2, limit]
for n in [2, √limit]:
if is_prime(n):
// eliminate multiples of each prime,
// starting with its square
is_prime(i) ← false, i ∈ {n², n²+n, n²+2n, ..., limit}
for n in [2, limit]:
if is_prime(n): print n
this is listed in wikipedia, and there is also another form which i
find even more complicated. but i dont understand how can i eliminate
multiples and all of the rest, if anyone could point me to an easy
explanation.
Thanks in advance...
>http://www.physicsforums.com/showthread.php?t=9298
Let me know if that thread doesn't answer your question and I'll take
another look.
Thanks,
Seth Rowe
If anyone else could give another hint, all things that are said in
that forum are kinda advanced to me..its all about datasets and
statusbars...i just wantend something to print prime numbers in a
textbox, using the sieve of eratosthenes...
thanks
Here's another article - I believe it uses the Sieve of Eratosthenes:
http://www.codeproject.com/cs/algori...imenumbers.asp
I also took the liberty of translating the code into VB for you - I
didn't test the algorithm completely though so be careful:
Sub Main()
' Change this for a different cutoff
Dim topNumber As Integer = 1000000
Dim numbers As BitArray = New BitArray(topNumber, True)
For i As Integer = 2 To topNumber - 1
If numbers(i) Then
For j As Integer = i * 2 To topNumber - 1 Step i
numbers(j) = False
Next
End If
Next
Dim primes As Integer = 0
For i As Integer = 1 To topNumber - 1
If numbers(i) Then
primes += 1
' Console.WriteLine(i.ToString())
End If
Next
Console.WriteLine()
Console.WriteLine("{0} out of {1} prime numbers found.",
primes, topNumber)
Console.Read()
End Sub
Thanks,
Seth Rowe
Thank you! This is very helpful. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: MSiegel |
last post by:
hi there!
i have to program the sieve of eratosthenes in php as a homework.
after i had created an html file where the maximum is set i wrote a
php script which doesn't work properly - actually...
|
by: Mark A. Washburn |
last post by:
/*
SIEVE OF ERATOSTHENES from BYTE magazine --------------------
-- compiled with jdk 1.1.7b with optimize on ( -O)
-- Run times on 300 MHz Pentium 2 Windows 95
-- in order of output, from...
|
by: Cmorriskuerten |
last post by:
HI,
is this is this solution to test if a number is a prime number or not:
/*
* Is n a prime number?
* Return TRUE (1): n is a prime number
* Return FALSE (0): n is a *not* a prime number...
|
by: someone else |
last post by:
hi all
I'm a newbie to this group. my apologies if I break any rules.
I've wrote a simple program to find the first 1,000,000 primes, and to find
all primes within any range (up to 200 *...
|
by: ckroom |
last post by:
Does anyone know a good algorithm to get the next prime of a number n?
prime = nextprime( n );
It's for some stuff about double rehashing, thanks.
--
ckroom
http://nazaries.net/~ckroom
|
by: Steve Bergman |
last post by:
Just wanted to report a delightful little surprise while experimenting
with psyco.
The program below performs astonoshingly well with psyco.
It finds all the prime numbers < 10,000,000
...
|
by: k1ckthem1dget |
last post by:
Can someone please help me with this program.
How would i go about writing a program which determines the prime numbers from 2 to 1000 in increasing order using the sieve method of Eratosthenes....
|
by: Fabrizio Romano |
last post by:
Hello,
I have a problem with a generic method.
I have written a sieve to generate prime numbers. This method takes an input
parameter which is the upperbound of the last prime I need to get. So...
|
by: jzakiya |
last post by:
This is to announce the release of my paper "Ultimate Prime Sieve --
Sieve of Zakiiya (SoZ)" in which I show and explain the development of
a class of Number Theory Sieves to generate prime...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
| |