Last active
January 27, 2018 18:36
-
-
Save ahmed-bhs/a8b8820225473c87621fed575ab4a245 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def listdiv(n): | |
L=[1] | |
fin=(n / 2) +1 | |
k=2 | |
while k<fin: | |
if n%k==0: | |
L +=[k] | |
k +=1 | |
return L | |
def est_parfait(n): | |
s=0 | |
t=listdiv(n) | |
# print(t) | |
if (t!=None): | |
for i in t : | |
s=s+i | |
if (s == n): | |
return True | |
else: | |
return False | |
def est_magique(n): | |
ch=str(n) | |
somme=0 | |
for k in range(2,8): | |
somme=somme+int(ch[k]) | |
if(est_parfait(somme) == True ): | |
return True | |
else: | |
return False | |
n=input("introduire valeur:"); | |
start=1 | |
for j in range(21000000,21999999): | |
number=str(j)[0:2] | |
if(number)=="21": | |
if( est_magique(j)== True): | |
print(j) | |
start+=1 | |
if(start==n): | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment