аватар question@mail.ru · 01.01.1970 03:00

The task is "minimum simple divider"

I just started to study Python on the Sirius platform. I was able to solve all other problems from the topic & laquo; While & raquo;, besides one task that does not allow me to go on the following topics. The task & laquo; the minimum simple divisor of the number & raquo;.

Condition: gives an integer that is no less than 2. Bring its smallest simple divisor. You can not use additional libraries (math, etc.)!

Input data: The whole positive number of n & lt; = 2*10 in the 9th degree.

Output: display the response to the task.

tried Decide by writing a code with While, but my answer is not counted, due to the program for too long. It is recommended that you organize a cycle that sorting out the dividers to the root from the n: While I*i & Lt; = N: , but I can’t understand how to do it.

my code Python (issues an error & laquo; the program was executed for too long and was interrupted & raquo; or & laquo; program; gives an error in the process of execution & raquo;):

  n =  int  ( input  ()) i =  2    when  i & lt; = n:   if%i! =  0 :  i +=  1    print  (i)     

I can not understand what the error is?

аватар answer@mail.ru · 01.01.1970 03:00

I would do this:

   def   prime_f  ( n ):   if  n% 2  ==  0 :  retu   2   i =  3    when  n%i! =  0   and  i*i & lt; = = " n:  i+=  2    if  i*i & lt; = n:  retu  it  retu  nn =  int  ( input  ())   print  (prime_f (n))     

we check 2 separate - Otherwise, n in itself simple.

Latest

Similar