Skip to main content
deleted 1 character in body; edited tags
Source Link
200_success
  • 144.2k
  • 22
  • 188
  • 473

I am implementing A064604 - OEIS for positive integers up to 10 billion.

I am finding the divisors in \$O(sqrt(N))\$\$O(\sqrt N)\$. So, the overall time complexity of running the formula right now is \$O(N*sqrt(N))\$\$O(N\sqrt N)\$. How do I improve on this?

Pastebin

import math

def factors(n):    
    return set(reduce(list.__add__, 
                ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))

def sigma_4(n):
    l = factors(n)
    ans=0
    for factor in l:
        ans += (pow(factor,4))
    return ans

n=int(raw_input())
ans=0
for i in xrange(1,n+1):
    ans+=sigma_4(i)
print ans

I am implementing A064604 - OEIS for positive integers up to 10 billion.

I am finding the divisors in \$O(sqrt(N))\$. So, the overall time complexity of running the formula right now is \$O(N*sqrt(N))\$. How do I improve on this?

Pastebin

import math

def factors(n):    
    return set(reduce(list.__add__, 
                ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))

def sigma_4(n):
    l = factors(n)
    ans=0
    for factor in l:
        ans += (pow(factor,4))
    return ans

n=int(raw_input())
ans=0
for i in xrange(1,n+1):
    ans+=sigma_4(i)
print ans

I am implementing A064604 - OEIS for positive integers up to 10 billion.

I am finding the divisors in \$O(\sqrt N)\$. So, the overall time complexity of running the formula right now is \$O(N\sqrt N)\$. How do I improve on this?

Pastebin

import math

def factors(n):    
    return set(reduce(list.__add__, 
                ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))

def sigma_4(n):
    l = factors(n)
    ans=0
    for factor in l:
        ans += (pow(factor,4))
    return ans

n=int(raw_input())
ans=0
for i in xrange(1,n+1):
    ans+=sigma_4(i)
print ans
Post Merged (destination) from codereview.stackexchange.com/questions/62200/…
deleted 30 characters in body; edited tags
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

I am implementing A064604 - OEIS for positive integers uptoup to 10 billion.

I am finding the divisors in O(sqrt(N))in \$O(sqrt(N))\$. So, the overall time complexity of running the formula right now is O(N*sqrt(N))\$O(N*sqrt(N))\$. How do I improviseimprove on this?

Code (Python) - http://pastebin.com/tYxRkqp2Pastebin

import math

def factors(n):    
    return set(reduce(list.__add__, 
                ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))

def sigma_4(n):
    l = factors(n)
    ans=0
    for factor in l:
        ans += (pow(factor,4))
    return ans

n=int(raw_input())
ans=0
for i in xrange(1,n+1):
    ans+=sigma_4(i)
print ans

I am implementing A064604 - OEIS for positive integers upto 10 billion.

I am finding the divisors in O(sqrt(N)). So, the overall time complexity of running the formula right now is O(N*sqrt(N)). How do I improvise on this?

Code (Python) - http://pastebin.com/tYxRkqp2

import math

def factors(n):    
    return set(reduce(list.__add__, 
                ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))

def sigma_4(n):
    l = factors(n)
    ans=0
    for factor in l:
        ans += (pow(factor,4))
    return ans

n=int(raw_input())
ans=0
for i in xrange(1,n+1):
    ans+=sigma_4(i)
print ans

I am implementing A064604 - OEIS for positive integers up to 10 billion.

I am finding the divisors in \$O(sqrt(N))\$. So, the overall time complexity of running the formula right now is \$O(N*sqrt(N))\$. How do I improve on this?

Pastebin

import math

def factors(n):    
    return set(reduce(list.__add__, 
                ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))

def sigma_4(n):
    l = factors(n)
    ans=0
    for factor in l:
        ans += (pow(factor,4))
    return ans

n=int(raw_input())
ans=0
for i in xrange(1,n+1):
    ans+=sigma_4(i)
print ans
Source Link
rayu
  • 129
  • 2

Optimizing code for sequence A064604

I am implementing A064604 - OEIS for positive integers upto 10 billion.

I am finding the divisors in O(sqrt(N)). So, the overall time complexity of running the formula right now is O(N*sqrt(N)). How do I improvise on this?

Code (Python) - http://pastebin.com/tYxRkqp2

import math

def factors(n):    
    return set(reduce(list.__add__, 
                ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))

def sigma_4(n):
    l = factors(n)
    ans=0
    for factor in l:
        ans += (pow(factor,4))
    return ans

n=int(raw_input())
ans=0
for i in xrange(1,n+1):
    ans+=sigma_4(i)
print ans