當前位置: 首頁>>代碼示例>>Python>>正文


Python Euler類代碼示例

本文整理匯總了Python中Euler的典型用法代碼示例。如果您正苦於以下問題:Python Euler類的具體用法?Python Euler怎麽用?Python Euler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Euler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: det_M

def det_M(seq):
    div1 = set(Euler.factoring(seq[0]))
    div2 = set(Euler.factoring(seq[1]))
    check = div2.difference(div1)
    if 3 in check or 7 in check:
        return 1
    else:
        return -1
開發者ID:zfhrp6,項目名稱:PE,代碼行數:8,代碼來源:ProjectEuler183.py

示例2: main

def main(limit):

	# Returns the number of unique numbers below limit that are the sum of a
	# prime square, prime cube, and prime fourth power.
	fourth_powers = [x ** 4 for x in Euler.prime_sieve(int(limit ** (1/4.0) + 1))]
	third_powers = [x ** 3 for x in Euler.prime_sieve(int(limit ** (1/3.0) + 1))]
	second_powers = [x ** 2 for x in Euler.prime_sieve(int(limit ** (1/2.0) + 1))]
	result = []
	for x in fourth_powers:
		for y in third_powers:
			for z in second_powers:
				if x+y+z < limit:
					result.append(x+y+z)
	return len(set(result))
開發者ID:Grae-Drake,項目名稱:Python_Euler,代碼行數:14,代碼來源:Problem_87.py

示例3: main

def main(n):

	# Returns the nth prime number.
	counter = 0
	testnum = 1
	while counter < n:
		testnum = Euler.nextPrime(testnum)
		counter += 1
	return testnum
開發者ID:Grae-Drake,項目名稱:Python_Euler,代碼行數:9,代碼來源:Problem_7.py

示例4: permutePrimes

def permutePrimes(prime, character):
    # Replaces each instance of character in prime with 0-9 and
    # returns a list of each resulting number that is also prime
    digits = [x for x in range(10)]
    digits = list(filter(lambda x: x != character, digits))
    answers = [prime]
    for x in digits:
        testnum = replaceDigit(prime, character, x)
        if Euler.isPrime(testnum) == True:
            if len(str(testnum)) == len(str(prime)):
                answers.append(testnum)
    return answers
開發者ID:Grae-Drake,項目名稱:Python_Euler,代碼行數:12,代碼來源:Problem_51.py

示例5: main

def main(limit):

	# Iterates through each number less than limit testing for primeness.
	# Counter is multiplied by each prime number for the a number of times
	# equal to the greatest number of times that prime divides a number less
	# than or equal to the limit.  For example, 2 divides 8 3 times (8 = 2*2*2),
	# so when limit == 10 counter is multiplied by 2^3.
	counter = 1
	for x in range(2, limit+1):
		if Euler.isPrime(x):
			counter *= (x ** math.floor(math.log(limit, x)))
	return counter
開發者ID:Grae-Drake,項目名稱:Python_Euler,代碼行數:12,代碼來源:Problem_5.py

示例6: naiveResilience

def naiveResilience(num):
    if(num==1): return 0/num
    if(Euler.isPrime(num,Euler.currPrimes)): return (num-1)/num
    count = 1
    for i in range(2,num):
        hit = False
        b = math.sqrt(num)
        for p in Euler.currPrimes:
            if(p>b): break
            if(i%p==0 and num%p==0):
                hit = True
                break
        if(not hit): count+=1
    return count/num
開發者ID:msimmara,項目名稱:NoSpeulers,代碼行數:14,代碼來源:Euler2.py

示例7: evaluate_prime

def evaluate_prime(prime):
    # Evaluates a prime number and adds a key: value pair to prime_table
    # with a list containing each set of pairs for that prime organized by
    # number of pairs

    candidate = Euler.previous_prime(prime)
    answer = []                                 # This will be the value we return
    finished = False
    pairs = [prime]
    while finished == False:
        while candidate > 2:
            if is_pair(prime, candidate) == True:
                pairs.append(candidate)
            candidate -= 2
        if len(pairs) > 1:
            answer.append((len(pairs), pairs))
            candidate = Euler.previous_prime(pairs[-1])
            pairs = pairs[:-1]
        if len(pairs) < 2:
            finished = True
    if len(answer) == 0:
        prime_table[prime] = False
    else:
        prime_table[prime] = answer
開發者ID:Grae-Drake,項目名稱:Python_Euler,代碼行數:24,代碼來源:Problem_60.py

示例8: euler243

def euler243():
    target = 15499/94744
    currentD = 1
    nextFactor = 2
    currFactorIndex = 0
    currR = 1
    while(currR>=target):
        print('Current index '+str(currFactorIndex))
        print('Current D '+str(currentD))
        currFactorIndex+=1
        if(len(Euler.currPrimes)<=currFactorIndex):
            Euler.currPrimes = Euler.primesList(nextFactor*2,Euler.currPrimes)
        nextFactor = Euler.currPrimes[currFactorIndex]
        currentD*=nextFactor
        currR = naiveResilience(currentD)
    print('D'+str(currentD))
    print('R'+str(currR))
開發者ID:msimmara,項目名稱:NoSpeulers,代碼行數:17,代碼來源:Euler2.py

示例9: euler243Heuristic

def euler243Heuristic():
    target = 15499/94744
    currentD = 1
    nextFactor = 2
    currFactorIndex = 0
    currR = 1
    while(currR>=target or True):
        currFactorIndex+=1
        if(len(Euler.currPrimes)<=currFactorIndex):
            Euler.currPrimes = Euler.primesList(nextFactor*2,Euler.currPrimes)
        nextFactor = Euler.currPrimes[currFactorIndex]
        currentD*=nextFactor
        currR = pseudoResilience(currFactorIndex)
        if(currR<target):
            print('Pseudo hit on Index '+str(currFactorIndex))
            print(currentD)
            print(currR)
        
    print('D'+str(currentD))
    print('R'+str(currR))
開發者ID:msimmara,項目名稱:NoSpeulers,代碼行數:20,代碼來源:Euler2.py

示例10: tagainiso

def tagainiso(n, m):
    re = list(set(Euler.factoring(n)) & set(Euler.factoring(m)))
    if re == [1]:
        re = []
    return re
開發者ID:zfhrp6,項目名稱:PE,代碼行數:5,代碼來源:ProjectEuler72.py

示例11: func

def func(x):
    ans = list(set(Euler.factoring(x)))
    ans.sort()
    return ans
開發者ID:zfhrp6,項目名稱:PE,代碼行數:4,代碼來源:ProjectEuler47.py

示例12: range

    # Problem 69: totient maximum

import time, Euler
t1 = time.clock()
answer = 1
n = 0
for x in range(2, 10001):
    rp_counter = 1
    for y in range(2,x):
        if Euler.highest_common_factor(x,y) == 1:
            rp_counter += 1
    ratio = x/rp_counter
    if ratio > answer:
        answer = ratio
        n = x

print(n, " has the largest ratio: ", answer)
            
t2 = time.clock()
print("Execution time: ", str(t2-t1)[:5])
開發者ID:Grae-Drake,項目名稱:Python_Euler,代碼行數:20,代碼來源:Problem_69.py

示例13: range

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
project euler problem 41

n桁の數がPandigitalであるとは, 1からnまでの數を各桁に1つずつもつことである.
例えば2143は4桁のPandigital數であり, かつ素數である.

n桁のPandigitalな素數の中で最大の數を答えよ.
"""
import Euler
import time
time1 = time.time()
answer = 0
for i in range(9999999, 1000000, -1):
    if Euler.pandigital_check(i) * Euler.primecheck(i):
        answer = i
        break

if answer == 0:
    for i in range(9999, 1000, -1):
        if Euler.pandigital_check(i) * Euler.primecheck(i):
            answer = i
            break

print(answer)
print(time.time() - time1, "seconds")
開發者ID:zfhrp6,項目名稱:PE,代碼行數:27,代碼來源:ProjectEuler41.py

示例14: Svenningsen

# Samuel Svenningsen (altock)
# Project Euler Problem 10
# import Euler_7
import Euler


if __name__ == '__main__':
    # NOTE: Sieve was too slow
    # erast = Euler_7.sieve()
    # erast.get_ith_prime(145000)
    # summation = sum(erast.list)
    # while erast.get_highest() < 2000000:
    #     summation += erast.next()
    # print summation - erast.get_highest()

    summation = 2
    for i in xrange(3, 2000000, 2):
        if Euler.is_prime(i):
            summation += i
    print summation
開發者ID:altock,項目名稱:dev,代碼行數:20,代碼來源:Euler_10.py

示例15: int

渦巻きに新しい層を付け加えよう.
すると辺の長さが9の渦巻きが出來る.
以下, この操作を繰り返していく.
対角線上の素數の割合が10%未満に落ちる最初の辺の長さを求めよ.
"""
import time
import math
import Euler
time1 = time.time()

amount = 0
p_amount = 0
c = 0
add_count = 0
add_num = 2
i = 1
while True:
    if amount != 0 and math.sqrt(i) % 1 == 0 and int(math.sqrt(i)) % 2 == 1:
        if p_amount * 10 <= amount:
            break
    if add_count == 4:
        add_count = 0
        add_num += 2
    i += add_num
    add_count += 1
    amount += 1
    if Euler.primecheck(i):
        p_amount += 1
print(math.sqrt(i), i)
print(time.time() - time1, "Seconds")
開發者ID:zfhrp6,項目名稱:PE,代碼行數:30,代碼來源:ProjectEuler58.py


注:本文中的Euler類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。