コード例 #1
0
def unconcealed(p, q):
    n = p*q
    phi = (p-1)*(q-1)
    es = [] #[e for e in range(1, phi) if gcd(e, phi) == 1]
    orders = {}

    e_cnts = [0] * phi

    for m in range(1, n):

        print(m)

        order = 1

        for g in [p, q]:

            #with euler_tools.Watch('Calculating order of %s in %s' % (m, g)):
            with euler_tools.Watch('Ordering'):
                _order, orders = get_order(m, g, orders)

            order *= _order

            #with euler_tools.Watch('Sieving'):
            #    g_es = e_sieve(order, phi)
                #print(len(g_es))
            #m_es.append(g_es)

        with euler_tools.Watch('Sieving'):
            m_es = e_sieve(order, phi)

        with euler_tools.Watch('Counting'):
            print(len(m_es))
            e_cnts = count_bad_ems(m_es, e_cnts, es, phi)
            #pass     
    return e_cnts
コード例 #2
0
ファイル: problem_72.py プロジェクト: pah8p/Project-Euler
def tester(n):
    def _key(z):
        return z[1][1]  #len(z[1])

    euler_tools.write_primes(int(n))
    primes = euler_tools.read_primes()
    with euler_tools.Watch():
        print(prime_divisor(9917, primes))
コード例 #3
0
def abc_hits(c_max):
    count = 0
    sum_c = 0
    with euler_tools.Watch('rads'):
        rads = radicals(c_max)

    for c in range(3, c_max):
        if c % 2500 == 0: print(c)

        for b in range(1, c):

            a = c - b

            #with euler_tools.Watch((a, b, c)):
            hit = abc_hit(a, b, c, rads)

            if hit:
                count += 1
                sum_c += c

    return count, sum_c
コード例 #4
0
def volume():
    rs = curve()
    rs.sort(key=lambda r: r[1], reverse=False)
    v = 0
    for n in range(1, len(rs)):
        x = (rs[n][0] + rs[n - 1][0]) / 2
        dy = rs[n][1] - rs[n - 1][1]
        v += PI * x**2 * dy
    return v


#parabola()

#print(r(PI/4))
with euler_tools.Watch():

    points = curve()
    points.sort(key=lambda r: r[1], reverse=False)

    print(_curve(50, points))
    print(integrate.quad(_curve, 0, 10, args=(points, )))

    #print(volume())

#print(t_from_theta(PI/4, PI/3))

#_t = t(PI/4, PI/3)

#print(_t, r_x(PI/3, _t), r_y(PI/3, _t))
コード例 #5
0
            #print(i, j, j-i)
            w[j] += w[j - i]
    return w[target]


def divisible_by(n):
    i = 1
    while True:

        m = partition(i)

        if str(m)[-6:] == '000000':
            #if m % 1e6 == 0:
            print(i, m)
            return None

        i += 1

        #if i % 10000 == 0:
        #    print(i, m)


import euler_tools

with euler_tools.Watch('abc'):

    partition(10)
    print(P)
    #print(ways(23000, 23000))
    print(divisible_by(1e6))
コード例 #6
0
            if i + j > n:
                break
    return pairs


def matrix():
    for n in range(1, 5):
        for m in range(1, 5):
            x = link_f(10**n, 10**m)
            print(n, m, sum([v for k, v in x.items()]))


N = 10**4
M = 10**3

# with euler_tools.Watch('a'):
#    _a = a(100)
#    print(_a)
#    for i, __a in enumerate(_a):
#        print(i, __a)

# with euler_tools.Watch('base'):
#    base = f(N, M)
#    print(len(base))

with euler_tools.Watch('link'):
    link = link_f(N, M)
    print(sum([v for k, v in link.items()]))

matrix()
コード例 #7
0
ファイル: problem_148.py プロジェクト: pah8p/Project-Euler
        return F[n]

    except KeyError:

        if n % 1e5 == 0: print(int(n / 1e5))

        if n < 7:
            F[n] = 0
            return 0

        p = int(math.log(n) / math.log(7))

        p7 = 7**p
        m = int(n / p7)
        mod = n % p7

        val = (p7 - mod - 1) * m + formula(mod) * (1 + m)

        if n < 3e7:
            F[n] = val

        return val


N = int(1e9)

import euler_tools

with euler_tools.Watch('formula'):
    print(sum(i - formula(i - 1) for i in range(1, int(N) + 1)))