Is 1 considered prime?

Is 1 considered prime?

Imagen de dotcsw

Wikipedia says that 1 is no longer considered prime by mathematicians. How should it be handled for the purposes of this challenge?

Looking at the example output from "primesums.exe 1 29 6 sumsout.txt" one thing I do not see is:
sum(1:9) = 27 = 3**3

So my guess is that 1 is not prime. This leads to my next question...

Can we assume that the first and second command line arguments are prime?

- Rick

publicaciones de 8 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.
Imagen de hitesh.sharma

Yeap u r right that 1 is not a prime number.
along with wiki where ever we see we find that 1 is neither prime not composite it lies in special category.
another url for ref : http://mathworld.wolfram.com/PrimeNumber.html.

so 1 is not prime.

Answet to your 2nd question.
1st & 2nd arguments are closed range, in mathematic terms [range1, range2]
means primes number should be in between these including them.

Imagen de Rama Kishan Malladi (Intel)

Yes, consider that 1 is not a prime. Good point: We would not pass "1" as the 1st parameter range1.

Thanks
-Rama

Imagen de dotcsw
Rama,

Quoting Rama Kishan Malladi (Intel) Good point: We would not pass "1" as the 1st parameter range1.

Does that mean the first and second parameters [range1, range2] will both be primes? It simplifies the logic slightly if we can assume that they are. Otherwise we have to search for the next prime >= range1 and the last prime <= range2.

- Rick

Imagen de hitesh.sharma

I do not think, it means that both parameters will be primes. They may be anything but both are inluded.

Imagen de Rama Kishan Malladi (Intel)

Please don't assume that range1 and range2 will be prime. Assume generic case.

Thanks
-Rama

Imagen de krivyakin

There are any tests except from task?

Imagen de dotcsw
Quoting dotcsw Looking at the example output from "primesums.exe 1 29 6 sumsout.txt" one thing I do not see is:
sum(1:9) = 27 = 3**3

Oops. That was a bad example. 9 is not prime.

- Rick

Inicie sesión para dejar un comentario.