mymath.py

Created by yaya-cout

Created on July 02, 2022

832 Bytes

Librairie pour voir si un nombre est premier et trouver ses facteurs premiers


from math import *
def isfirst(nombre):
  diviseurs = []
  for diviseur in range(1,nombre):
    division = nombre / diviseur
    if division == int(division):
      diviseurs.append(diviseur)
    if len(diviseurs) == 2:
      break
  if len(diviseurs) == 1:
    return True
  else:
    return False
def get_factors(nombre):
    if nombre < 2:
      return []
    i=0
    facteurs_premiers = []
    while True:
      if isfirst(nombre):
        break
      if isfirst(i):
        pass
      for i in range(2,nombre):
          division = nombre / i
          if division == int(division):
            nombre = division
            if isfirst(nombre):
              facteurs_premiers.append(int(nombre))
            if isfirst(i):
              facteurs_premiers.append(i)
            break
    return facteurs_premiers

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.