Exemplo n.º 1
0
def hamming(smooth,power):

    bound = 10**power
    '''
    prime_list = []                         # Generate the prime numbers
    for i in range(smooth+1):
        if isPrime(i):
            prime_list.append(i)
    '''
    prime_list = sieve(smooth+1)
            
    prime_list.reverse()                    # Speeds up calculation
    exp_list = []                           # Determine the maximum exponents can be
    for prime in prime_list:
        exp_list.append(int(log(bound)/log(prime)))
    print exp_list

    hcount, count = 0, 1
    lim = [0]*len(prime_list)               # List to carry exponents
    final = hform(prime_list, exp_list, lim, bound, count, hcount)
    
    print '\nThere are %s Hamming numbers of type %s not exceeding 10^%s' % (final, smooth, power)
    print '\tFound in %s seconds' % clock()
    print '\tThere are %s Primes that include: %s' % (len(prime_list),prime_list)
    print '\tThe calculated Exponent limits: %s\n' % exp_list
Exemplo n.º 2
0
def hamming(smooth, power):

    bound = 10**power
    '''
    prime_list = []                         # Generate the prime numbers
    for i in range(smooth+1):
        if isPrime(i):
            prime_list.append(i)
    '''
    prime_list = sieve(smooth + 1)

    prime_list.reverse()  # Speeds up calculation
    exp_list = []  # Determine the maximum exponents can be
    for prime in prime_list:
        exp_list.append(int(log(bound) / log(prime)))
    print exp_list

    hcount, count = 0, 1
    lim = [0] * len(prime_list)  # List to carry exponents
    final = hform(prime_list, exp_list, lim, bound, count, hcount)

    print '\nThere are %s Hamming numbers of type %s not exceeding 10^%s' % (
        final, smooth, power)
    print '\tFound in %s seconds' % clock()
    print '\tThere are %s Primes that include: %s' % (len(prime_list),
                                                      prime_list)
    print '\tThe calculated Exponent limits: %s\n' % exp_list
Exemplo n.º 3
0
def e214(n=25,t = 4*10**7):
    p = list(sieve(t))
    count = 0
    print('start')
    mini = 1000
    for num in p:
        if num>mini:print(num/p[-1],end='\r');mini+=1000
        if chain(num)==n:count+=num
    return count
Exemplo n.º 4
0
def fsandexp(n,pfs=[]):
    if n==1:return []
    if isprime2(n):return [n]
    #p = sieve(int(n**.5)+1)
    for i in sieve(int(n**.5)+1):
        if n%i==0:
            n//=i
            pfs+=[i]
            #if n==1:return [i]
            return [i]+fsandexp(n,pfs)
Exemplo n.º 5
0
def fsandexp(n,pfs=[]):
    if n==1:return []
    if isprime3(n):return [n]
    p = list(sieve(int(n**.5)+1))
    for i in p:
        if n%i==0:
            n//=i
            pfs+=[i]
            #if n==1:return [i]
            return [i]+fsandexp(n,pfs)
Exemplo n.º 6
0
def fs(n,pfs=[]):
    if isprime2(n):return [n]
    p = sieve(int(n**.5)+1)
    exp = 0
    for i in p:
        if n%i==0:
            while n%i==0:
                n//=i
            pfs+=[i]
            if n==1:return [i]
            return [i]+fs(n,pfs)
Exemplo n.º 7
0
def fsandexp(n, pfs=[]):
    if n == 1:
        return []
    if isprime2(n):
        return [n]
    # p = sieve(int(n**.5)+1)
    for i in sieve(int(n ** 0.5) + 1):
        if n % i == 0:
            n //= i
            pfs += [i]
            # if n==1:return [i]
            return [i] + fsandexp(n, pfs)
Exemplo n.º 8
0
def test(c=25,n = 4*10**7):
    plist = phi(n)
    print('pdone')
    count = 0
    for i in sieve(4*10**7):
        j = i
        chain = 1
        while chain<=25 and j!=1:
            j = plist[j]
            chain+=1
        if chain==25:count+=i
    return count
Exemplo n.º 9
0
def fs(n, pfs=[]):
    if isprime2(n):
        return [n]
    p = sieve(int(n ** 0.5) + 1)
    exp = 0
    for i in p:
        if n % i == 0:
            while n % i == 0:
                n //= i
            pfs += [i]
            if n == 1:
                return [i]
            return [i] + fs(n, pfs)
Exemplo n.º 10
0
def e010(top=2 * 10**6):
    return sum(sieve(top))
Exemplo n.º 11
0
def e010(top=2*10**6):
    return sum(sieve(top))