示例#1
0
文件: p073.py 项目: nonette/euler
def p073(N=12000):
    retval = 0
    for d in range(2,N+1):
        total = p069.phi(d)
        lowerthird = len([n for n in range(d/3+1) if numty.gcd(n,d) == 1])
        retval += total/2-lowerthird
    return retval
示例#2
0
文件: p075.py 项目: nonette/euler
def uniques(N):
    table = [[] for n in range(N+1)]
    for k in range(1,N/12+1):
        for mplusn in range(3,int(math.sqrt(N/k))+1,2):
            for m in range(mplusn/2+1, mplusn):
                p = 2*k*m*mplusn
                if p > N:
                    break
                if numty.gcd(m,mplusn) != 1:
                    continue
                table[p].append((k,mplusn-m,m))

    return [p for p in range(len(table)) if len(table[p]) == 1]
示例#3
0
文件: p075.py 项目: nonette/euler
def uniques(N):
    table = [[] for n in range(N + 1)]
    for k in range(1, N / 12 + 1):
        for mplusn in range(3, int(math.sqrt(N / k)) + 1, 2):
            for m in range(mplusn / 2 + 1, mplusn):
                p = 2 * k * m * mplusn
                if p > N:
                    break
                if numty.gcd(m, mplusn) != 1:
                    continue
                table[p].append((k, mplusn - m, m))

    return [p for p in range(len(table)) if len(table[p]) == 1]
示例#4
0
def p127(N=120000):
    rad_table = radtable(N)
    a_table = sorted([(rad_table[a], a) for a in xrange(1, N)])
    acc = 0

    for c in xrange(N):
        lim = c / rad_table[c]
        for rad_a, a in a_table:
            if rad_a > lim:
                break
            if a >= (c + 1) / 2:
                continue
            if numty.gcd(rad_table[a], rad_table[c]) == 1:
                if rad_table[a] * rad_table[c - a] * rad_table[c] < c:
                    logger.debug('%d %d %d' % (a, c - a, c))
                    acc += c
    return acc
示例#5
0
文件: p127.py 项目: nonette/euler
def p127(N = 120000):
    rad_table = radtable(N)
    a_table = sorted([(rad_table[a], a) for a in xrange(1,N)])
    acc = 0

    for c in xrange(N):
        lim = c/rad_table[c]
        for rad_a, a in a_table:
            if rad_a > lim:
                break
            if a >= (c+1)/2:
                continue
            if numty.gcd(rad_table[a],rad_table[c]) == 1:
                if rad_table[a]*rad_table[c-a]*rad_table[c] < c:    
                    logger.debug('%d %d %d' % (a, c-a, c))
                    acc += c
    return acc
示例#6
0
def lcm(a, b):
    return a * b / numty.gcd(a, b)
示例#7
0
文件: p005.py 项目: nonette/euler
def lcm(a,b):
    return a*b/numty.gcd(a,b)