TOPIC

Python TLE ajuda

Arthur asked 4 years ago

from math import floor

def a000217(n):
    product = (-1) ** n
    summatory = 0
    for k in range(1, n + 1):
        summatory += (-1) ** k * k ** 2
    return product * summatory

def a153485(n):
    summatory = 0
    for k in range(1, n + 1):
        summatory += k * floor((n - k) / k)
    return summatory

def a004125(n):
    return a000217(n - 1) - a153485(n)

def a024916(n):
    return n ** 2 - a004125(n)

while True:
    n = int(input())
    if n == 0:
        break
    print(a024916(n))

Pesquisei várias sequencias pra me ajudar mas mesmo assim ta dando tle : (

This topic has not been answered yet. Be the first!

Remember not post solutions. Your post may be reviewed by our moderators.