nombreparfait.py

Created by florian-allard

Created on June 06, 2018

252 Bytes

Renvoie la liste des nombres parfaits (nombre égal à la somme de ses diviseurs propres), pour les nombres entiers inférieurs à 1000.


from math import *
for n in range(1,1001):
  somme=0
  for i in range(2,int(sqrt(n))+1):
    if n%i==0:
      somme += i+n/i  #on a commence la boucle a 2 pour ne pas ajouter 1 et n aux diviseurs      
  if somme==n-1:
    print(n)

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.