3744 - ELHC: Difference between revisions

From Bitnami MediaWiki
Raul (talk | contribs)
Pagină nouă: def prim(n): cnt = 0 for i in range(1, int(n) + 1): if n % i == 0: cnt += 2 if i * i == n: cnt -= 1 if cnt == 2: return 1 else: return 0 if __name__ == '__main__': n = int(input()) for i in range(2, n + 1): if prim(i): print(i, end=' ')
 
Raul (talk | contribs)
No edit summary
Line 1: Line 1:
def prim(n):
def prim(int n):
     cnt = 0
     cnt = 0
     for i in range(1, int(n) + 1):
     for i in range(1, int(n) + 1):

Revision as of 15:05, 4 December 2023

def prim(int n):

   cnt = 0
   for i in range(1, int(n) + 1):
       if n % i == 0:
           cnt += 2
       if i * i == n:
           cnt -= 1
   if cnt == 2:
       return 1
   else:
       return 0


if __name__ == '__main__':

  n = int(input())
  for i in range(2, n + 1):
      if prim(i):
  print(i, end=' ')