Skip to content

Instantly share code, notes, and snippets.

@tpopp
Created August 3, 2013 04:14
Show Gist options
  • Save tpopp/6145152 to your computer and use it in GitHub Desktop.
Save tpopp/6145152 to your computer and use it in GitHub Desktop.
# improve A(n)
# H(n) improves by working from both sides in at the same time
def A(n):
res = 0
for i in range(1,n+1):
res += n // i
return res
def H(n):
if (n == 1):
return 1
i = 1
val = n
count = 0
while (i < val):
val = n//i
count += val + i * (val - n//(i + 1)) #second portion sums all i's that would appear later
i += 1
if (i != val):
count -= val
return count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment