|   | 1 |  initial version  | 
Your loop "computes" the answers as strings. It would be better to compute them as rational numbers. For example:
def my_function(k=51):
    L = []
    for n in range(1, k):
        a = n**2 + 1
        b = (n+1)**2 + 1
        c = 2*n
        primes = sum(1 for p in prime_range(a, b))
        # QQ(...) converts the argument to a rational number
        L.append(QQ(nprimes/c).denominator())
    return L
Then you can run lcm(L).
|   | 2 |  No.2 Revision  | 
Your loop "computes" the answers as strings. It would be better to compute them as rational numbers. For example:
def my_function(k=51):
    # L = list in which to collect the answers
    L = []
    for n in range(1, k):
        a = n**2 + 1
        b = (n+1)**2 + 1
        c = 2*n
        primes = sum(1 for p in prime_range(a, b))
        # QQ(...) converts the argument to a rational number
        # L.append(...) appends the argument to L
        L.append(QQ(nprimes/c).denominator())
    return L
Then you can run lcm(L).
|   | 3 |  No.3 Revision  | 
Your loop "computes" the answers as strings. It would be better to compute them as rational numbers. For example:
def my_function(k=51):
    # L = list in which to collect the answers
    L = []
    for n in range(1, k):
        a = n**2 + 1
        b = (n+1)**2 + 1
        c = 2*n
        primes nprimes = sum(1 for p in prime_range(a, b))
        # QQ(...) converts the argument to a rational number
        # L.append(...) appends the argument to L
        L.append(QQ(nprimes/c).denominator())
    return L
Then you can run lcm(L).
 Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.
 
                
                Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.