Giter VIP home page Giter VIP logo

mpiprimes's People

Contributors

serghov avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

mpiprimes's Issues

isPrime function is not correct

Hi - thank you for this example MPICH program which is brilliant as a test. However, your code for prime numbers does not give the correct answer. I used 100,000 and there should be 9,592 primes but your program lists 9,656.

  • It does not include 2 as a prime number
  • But lists the following as primes, when they are not;
	1, 	9, 	25, 	49, 	121, 	169, 	289, 	361, 
	529, 	841, 	961, 	1369, 	1681, 	1849, 	2209, 	2809, 
	3481, 	3721, 	4489, 	5041, 	5329, 	6241, 	6889, 	7921, 
	9409, 	10201, 	10609, 	11449, 	11881, 	12769, 	16129, 	17161, 
	18769, 	19321, 	22201, 	22801, 	24649, 	26569, 	27889, 	29929, 
	32041, 	32761, 	36481, 	37249, 	38809, 	39601, 	44521, 	49729, 
	51529, 	52441, 	54289, 	57121, 	58081, 	63001, 	66049, 	69169, 
	72361, 	73441, 	76729, 	78961, 	80089, 	85849, 	94249, 	96721, 
	97969

My solution was the following, there might be neater ways of doing it:

        if (num < 2)
                return 0;
        for (int i = 2; i <= sqrt(num); i++)
        {
                if ((num % i) == 0)
                        return 0;
        }
        return 1;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.