primes

This is a discussion on primes within the C++ Programming forums, part of the General Programming Boards category; hello everyone. the is a real pain in the neck...can anyone help me write a program that determines all the ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    4

    primes

    hello everyone.

    the is a real pain in the neck...can anyone help me write a program that determines all the preimes from 1 to 1000 , counts them, and determine if any of the primes are carmuichael numbers...i donot know what the hell they are !!

    HELP !!!!

    i got this program from a friend but it only calculates the primes up to 100, how do i extend it to 1000 ??

    #include <iostream.h>


    void main(){
    //declarations
    int var1;
    int var2;
    int flag;
    //tells that the user will see all the prime numbers up too 100
    cout << "All of the prime numbers up to 100 are...\n";
    //calculations


    for(var1 = 2; var1 <= 100; var1++){
    flag = 1;


    for(var2 = 2; var2 < var1; var2++){


    if((int)var1 % (int)var2 == 0){
    flag = 0;
    }
    }
    //output...


    if(flag == 1){
    cout << var2;
    cout << " ";
    }
    }
    cout << " ";
    }
    Last edited by godfather; 05-08-2002 at 02:32 AM.

  2. #2
    www.entropysink.com
    Join Date
    Feb 2002
    Posts
    605
    OK, here's some hints.

    1). Is a Carmichael number prime?

    2).>> i got this program from a friend but it only calculates the primes up to 100, how do i extend it to 1000 ??

    for(var1 = 2; var1 <= 100; var1++)

    3). Lastly, you don't need to check out all the values from 2 to var1, you only need to check up to the square root of var1.

    You may also want to search this site. The question has been asked sooooooo many times before. Also search for the Sieve of Erasthones here and on the web.
    Visit entropysink.com - It's what your PC is made for!

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,418
    http://primes.utm.edu/glossary/page....aelNumber.html

    The Carmichael numbers under 100,000 are

    561, 1105, 1729, 2465, 2821, 6601, 8911, 10585, 15841, 29341, 41041, 46657, 52633, 62745, 63973, and 75361.
    Gonna be a dull answer upto 1000

    Code:
    int main ( ) {
        printf( "The Carmichael numbers under 1000 are: 561\n" );
        return 0;
    }

  4. #4
    Evil Member
    Join Date
    Jan 2002
    Posts
    638
    Not exactly.

    ALL primes are carmichael numbers. Those numbers are the rare composite carmichael numbers.

    Erm sorry I wrote that wrong. All primes satisfy the test for carmichael numbers, but the distinction of carmicheal numbers is only applies to those composite numbers which also pass the test.

    So, there are no prime carmicheal numbers under 1000, or under any maximum.
    Last edited by Imperito; 05-08-2002 at 01:50 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Messene Primes
    By mrsirpoopsalot in forum C++ Programming
    Replies: 9
    Last Post: 01-31-2009, 09:32 PM
  2. Finding primes
    By scwizzo in forum C++ Programming
    Replies: 11
    Last Post: 09-10-2008, 06:15 PM
  3. primes program need some help
    By Mshock in forum C Programming
    Replies: 2
    Last Post: 04-17-2006, 07:21 PM
  4. a program that writes the primes
    By Geo-Fry in forum C++ Programming
    Replies: 8
    Last Post: 03-29-2003, 05:37 PM
  5. Generating Primes !?!?!?!
    By Moni in forum C++ Programming
    Replies: 12
    Last Post: 03-16-2003, 06:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21