Thread: Prime Sieve Help

  1. #1
    Registered User
    Join Date
    Apr 2011


    Heres my problem. I completed a sieve originally that did not include sqrt or dividing just by odd numbers other then 2. But when I used it, it was too slow for the really big numbers so, I was told that in order to fix it the best thing to do was to just use the sqrt of the the original number and to only divide by 2 and odd numbers. However when I went to implement this it has not worked so well and Im at a loss, to know how to fix it.
    Heres the the part of the codes thats the problem. The user inputs the range of numbers of course the sieve finds the primes within the range. The only specifications of the range is that of course its positive and that the end is larger then the beginning.

    void getPrime(int start, int end)
    int numbs;
    int numprimes;
    int num1 = START;
    int num2 = START;
    int num3 = START;

    for (start = sqrt(start); start <= end; start++)
    numbs = START;
    for (numprimes = 3; numprimes < sqrt(start); numprimes += 2)
    if(start % 2 == START)
    numbs = numbs + 1;
    else if(start % numprimes == START) // Not a prime if yes
    numbs = numbs + 1;
    if((numbs == START)) // prime if yes
    if( start >= 2)
    num3 = num2;
    num2 = num1;
    num1 = start;

    if(num3 == START && num2 == START)
    else if (num3 == START)
    printf("Prime numbers:\n\n");
    printf("%d\n", num2);
    else if (((num1 + num3) / AVG) == num2)
    printf("%d is a balanced prime.\n", num2);
    else if (((num1 + num3) / AVG) > num2)
    printf("%d is a weak prime.\n", num2);
    else if(((num1 + num3) / AVG) < num2)
    printf("%d is a strong prime.\n", num2);
    printf("%d\n", num1);
    Right now this is printing only part of the primes and the primes it is printing, its printing multiple times.

    my bad START = 0 and AVG = 2 for clarification.
    Last edited by sellefrancais; 04-03-2011 at 02:15 PM.

  2. #2
    Join Date
    Aug 2010
    Ontario Canada

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Quote Originally Posted by guy who is afraid of code tags
    I completed a sieve originally that did not include sqrt or dividing just by odd numbers other then 2
    I loled.

    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Idea for a fast and efficient prime sieve
    By Sebastiani in forum General Discussions
    Replies: 2
    Last Post: 06-21-2010, 07:26 AM
  2. Replies: 2
    Last Post: 12-24-2009, 02:41 AM
  3. Need help creating prime number program
    By dauden6 in forum C++ Programming
    Replies: 4
    Last Post: 07-17-2009, 03:50 PM
  4. Prime Sieve Optimization
    By rt454 in forum C++ Programming
    Replies: 9
    Last Post: 05-30-2008, 10:22 PM
  5. prime number program with function
    By mackieinva in forum C Programming
    Replies: 17
    Last Post: 09-20-2007, 09:36 AM

Tags for this Thread

Website Security Test