473,394 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

finding prime numbers

hsn
237 100+
i want to find the prime number in a list from 2 to 1000000
which algorithm is the best one to find the prime numbers in a really fast way.

thanks in advance

hsn
Jan 26 '08 #1
8 2752
sicarie
4,677 Expert Mod 4TB
What algorithms are you looking at?
Jan 26 '08 #2
hsn
237 100+
if you have a list 2 10
i want to find an algorithm that will find the prime numbers 2,3,5,7 very fast.
but in a list 2 to 1000000 .
like sieve algorithm. but the problem is that i don't understand exactly how to implement it correctly in C++

please guys i need some guidings

hsn
Jan 26 '08 #3
sicarie
4,677 Expert Mod 4TB
Okay, what parts of the sieve algorithm don't you know how to implement?
Jan 26 '08 #4
hsn
237 100+
the loops
how to go through it exactly that what i getting some problems in understanding it.
and what should i use to delete the values from the list (what type of list should i use).

thanks
Jan 26 '08 #5
sicarie
4,677 Expert Mod 4TB
Okay, well, let's make sure we're talking about the same one, first. I believe you're speaking of the Sieve of Eratosthenes ?

What parts of that don't you understand? Did you walk through the algorithm by hand for a smaller set? Like 1 - 50? Or maybe 1 to 30? Just enough so you can understand how it works?
Jan 26 '08 #6
Menso
1
A code like this won't be as fast as possible, but it will find primes with that method.

Expand|Select|Wrap|Line Numbers
  1. code removed, please read posting guidelines
Jan 26 '08 #7
hsn
237 100+
yes i have tried this algorithm and walked through some examples
but when i want to code it i have some problems
i am not sure what to use. should i use vectors, dynamic arrays
i don't know exactly what to use.
and if there is an algorithm to find the prime numbers from 2 to 1000000 which is faster than sieve i would be greatful.
i am particepating in an online judge and my answer give time limit crossed
i have only 3 seconds to solve it and i pass that limit all the time.
Jan 26 '08 #8
hsn
237 100+
i have seen that link before i post my question here. i just need some explnation in what to use in coding.
Jan 26 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

36
by: Dag | last post by:
Is there a python module that includes functions for working with prime numbers? I mainly need A function that returns the Nth prime number and that returns how many prime numbers are less than N,...
9
by: Greg Brunet | last post by:
In doing some testing of different but simple algorithms for getting a list of prime numbers, I ended up getting some results that seem a bit contradictory. Given the following test program...
32
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 *...
19
by: gk245 | last post by:
Trying to write a program that will figure out if a number is perfect or not. Here is my logic: 1) Read in the number 2) Split it up (number - 1) 3) Put all the split up numbers into an...
25
by: johnmsimon | last post by:
i need to develop a code that finds a prime right number between 2 and 100000. and print one line of text that indicates if the int. is right prime. i am in beginning programing so complex is...
60
by: rhle.freak | last post by:
Here is my code to generate prime numbers.It works absolutely fine when the range is *not very large*. However on initializing i with a large integer it produces erroneous results (some numbers...
7
by: newstips6706 | last post by:
1, 2, 3, 5, 7... PRIME Numbers ________________________________ Definitions What is a PRIME Number ?
2
by: jknox13 | last post by:
Hi, I have to find the divisors of all numbers less than a number inputed by the user and state if a number is prime if no divisors. I have this code so far, but I'm getting the wrong output and...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.