Home python Effective algorithm for the output of simple numbers

Effective algorithm for the output of simple numbers




Trying to bring all the simple numbers to 1000. I can not understand what the problem is, but only the first number is displayed:

def prime (x):
  D = 2.
  While x% d! = 0:
    D + = 1
For i in Range (1,1000):
  IF Prime (I):
    Print (i, End = '')

Answer 1, Authority 100%

You cheat, this code does not output anything at all. But if you replace Range (1,1000) on Range (2,1000) , it will bring all simple up to 1000.

and does not output because the cycle

while x% d! = 0:
  D + = 1

at x = 1 and the initial value d = 2 will never end.

Answer 2, Authority 100%

That’s how:

for n in range (2, 1001):
  IF ALL (N% i! = 0 for i in Range (2, N)):
    Print (N)

For simple up to a thousand no sense to apply some effective algorithms

Answer 3, Authority 100%

problem in the use of units – cycle inside Prime Endless turns out

for i in range (2,1000):

and everything will work

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions