当前位置: 首页>>代码示例>>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;未经允许,请勿转载。