def primos_maiores_que_n(n, lim):
return primos_menores_que_n(lim, start=n)
def maior_primo(n):
for num in reversed(range(1,n+1)):
if all(num%i!=0 for i in range(2,num)):
return num
def e_primo(num):
return all(num%i!=0 for i in range(2,num))
def primos_menores_que_n(n, start=1):
for num in range(start,n):
if all(num%i!=0 for i in range(2,num)):
yield num
print(list(primos_menores_que_n(10))) # [1, 2, 3, 5, 7]
print(list(primos_maiores_que_n(10, 100))) # [11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
print(maior_primo(100)) # 97
print(e_primo(10)) # False
print(e_primo(11)) # True
ZGVmIHByaW1vc19tYWlvcmVzX3F1ZV9uKG4sIGxpbSk6CiAgICByZXR1cm4gcHJpbW9zX21lbm9yZXNfcXVlX24obGltLCBzdGFydD1uKQoKZGVmIG1haW9yX3ByaW1vKG4pOgogICAgZm9yIG51bSBpbiByZXZlcnNlZChyYW5nZSgxLG4rMSkpOgogICAgICAgIGlmIGFsbChudW0laSE9MCBmb3IgaSBpbiByYW5nZSgyLG51bSkpOgogICAgICAgICAgICByZXR1cm4gbnVtCgpkZWYgZV9wcmltbyhudW0pOgogICByZXR1cm4gYWxsKG51bSVpIT0wIGZvciBpIGluIHJhbmdlKDIsbnVtKSkKCmRlZiBwcmltb3NfbWVub3Jlc19xdWVfbihuLCBzdGFydD0xKToKICAgIGZvciBudW0gaW4gcmFuZ2Uoc3RhcnQsbik6CiAgICAgICAgaWYgYWxsKG51bSVpIT0wIGZvciBpIGluIHJhbmdlKDIsbnVtKSk6CiAgICAgICAgICAgIHlpZWxkIG51bQoKcHJpbnQobGlzdChwcmltb3NfbWVub3Jlc19xdWVfbigxMCkpKSAjIFsxLCAyLCAzLCA1LCA3XQpwcmludChsaXN0KHByaW1vc19tYWlvcmVzX3F1ZV9uKDEwLCAxMDApKSkgIyBbMTEsIDEzLCAxNywgMTksIDIzLCAyOSwgMzEsIDM3LCA0MSwgNDMsIDQ3LCA1MywgNTksIDYxLCA2NywgNzEsIDczLCA3OSwgODMsIDg5LCA5N10KcHJpbnQobWFpb3JfcHJpbW8oMTAwKSkgIyA5NwpwcmludChlX3ByaW1vKDEwKSkgIyBGYWxzZQpwcmludChlX3ByaW1vKDExKSkgIyBUcnVl
[1, 2, 3, 5, 7]
[11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
97
False
True