@acwoss/

GlumStunningRouter

Python

No description

fork
loading
Files
  • main.py

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.17398461351009997","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"aW1wb3J0IG1hdGgsIHRpbWUKCmRlZiBzaWV2ZV9vZl9lcmF0b3N0aGVuZShOKToKCiAgICAjIENyaWEtc2UgdW1hIGxpc3RhIHJlZmVyZW50ZSBhIHRvZG9zIG9zIGludGVpcm9zIGVudHJlIDAgZSBOOgogICAgQSA9IFtUcnVlXSAqIChOKzEpCgogICAgIyBEZWZpbmUgb3MgbsO6bWVyb3MgMCBlIDEgY29tbyBuw6NvIHByaW1vczoKICAgIEFbMF0gPSBBWzFdID0gRmFsc2UKCiAgICAjIFBlcmNvcnJhIGEgbGlzdGEgYXTDqSBlbmNvbnRyYXIgbyBwcmltZWlybyBuw7ptZXJvIHByaW1vOgogICAgZm9yIHZhbHVlLCBwcmltZSBpbiBlbnVtZXJhdGUoQSk6CgogICAgICAgICMgTyBuw7ptZXJvIMOpIHByaW1vPwogICAgICAgIGlmIHByaW1lOgoKICAgICAgICAgICAgIyBSZXRvcm5hIG8gbsO6bWVybyBwcmltbzoKICAgICAgICAgICAgeWllbGQgdmFsdWUKCiAgICAgICAgICAgICMgUmVtb3ZhIGRhIGxpc3RhIHRvZG9zIG9zIG3Dumx0aXBsb3MgZG8gbsO6bWVybyBlbm9udHJhZG86CiAgICAgICAgICAgIGZvciBpIGluIHJhbmdlKHZhbHVlKioyLCBOKzEsIHZhbHVlKToKICAgICAgICAgICAgICAgIEFbaV0gPSBGYWxzZQoKc3RhcnQgPSB0aW1lLnRpbWUoKQoKIyBQZXJjb3JyZSBhIGxpc3RhIGRlIG7Dum1lcm9zIHByaW1vcyBtZW5vcmVzIHF1ZSBOOgpmb3IgcHJpbWUgaW4gc2lldmVfb2ZfZXJhdG9zdGhlbmUoNTAwKToKCiAgICAjIENhbGN1bGEgbyB2YWxvciBkZSBuIHF1ZSBkZWZpbmUgbyBQbjoKICAgIG4gPSBtYXRoLmxvZzIocHJpbWUrMSkKCiAgICAjIFZlcmlmaWNhIHNlIG4gw6kgaW50ZWlybywgc2VuZG8gdW0gcHJpbW8gZGUgTWVyc2VubmU6CiAgICBpc19tZXJzZW5uZSA9IG4uaXNfaW50ZWdlcigpCgogICAgIyBTZSBmb3IgdW0gcHJpbW8gZGUgTWVyc2VubmUsIGNhbGN1bGEgbyBuw7ptZXJvIHBlcmZlaXRvOgogICAgaWYgaXNfbWVyc2VubmU6CiAgICAgICAgcHJpbnQoMioqKG4tMSkgKiBwcmltZSkKCnByaW50KGYnVGVtcG8gZGUgZXhlY3XDp8Ojbzoge3RpbWUudGltZSgpIC0gc3RhcnR9cycp"},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import math, time

def sieve_of_eratosthene(N):

    # Cria-se uma lista referente a todos os inteiros entre 0 e N:
    A = [True] * (N+1)

    # Define os números 0 e 1 como não primos:
    A[0] = A[1] = False

    # Percorra a lista até encontrar o primeiro número primo:
    for value, prime in enumerate(A):

        # O número é primo?
        if prime:

            # Retorna o número primo:
            yield value

            # Remova da lista todos os múltiplos do número enontrado:
            for i in range(value**2, N+1, value):
                A[i] = False

start = time.time()

# Percorre a lista de números primos menores que N:
for prime in sieve_of_eratosthene(500):

    # Calcula o valor de n que define o Pn:
    n = math.log2(prime+1)

    # Verifica se n é inteiro, sendo um primo de Mersenne:
    is_mersenne = n.is_integer()

    # Se for um primo de Mersenne, calcula o número perfeito:
    if is_mersenne:
        print(2**(n-1) * prime)

print(f'Tempo de execução: {time.time() - start}s')