当前位置: 首页>>代码示例>>Python>>正文


Python sympy.isprime函数代码示例

本文整理汇总了Python中sympy.isprime函数的典型用法代码示例。如果您正苦于以下问题:Python isprime函数的具体用法?Python isprime怎么用?Python isprime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了isprime函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

def main():
    summa = 0
    for num in range(1,150000001):
        arr_num = []
        arr_const = [1,3,7,9,13,27]
        
        #List to hold all possible values
        for i in arr_const:
            var = ((num**2)+i)
            if(sp.isprime(var)):
                arr_num.append(var) 
                
        count = len(arr_num)
              
        #Number of primes between two numbers
        count_prime = 0
        for k in range((num**2)+1,(num**2)+27+1):
            if(sp.isprime(k)):
                count_prime += 1
        
        if(count == 6):
            if(count == count_prime):
                print num
                summa += num
            
    print "Total : " + str(summa)
开发者ID:KartikKannapur,项目名称:Programming_Challenges,代码行数:26,代码来源:146.py

示例2: euler58

def euler58():
    cnt = 1
    prime_cnt = 0
    n = 2
    while True:
        prime_cnt += isprime(4 * n * n - 10 * n + 7)
        prime_cnt += isprime(4 * n * n - 8 * n + 5)
        prime_cnt += isprime(4 * n * n - 6 * n + 3)
        cnt += 4
        if prime_cnt * 1.0 / cnt < 0.1:
            return n * 2 + 1
        n += 1
开发者ID:iynaix,项目名称:eulerproject,代码行数:12,代码来源:euler058.py

示例3: keycreation

def keycreation(p, q, e):
    n = p * q

    # check p, q are primes
    if not(isprime(p) and isprime(q)):
        raise Exception('p, q are not primes')

    # check gcd(e, (p-1)(q-1))=1
    if (gcd(e, (p-1) * (q-1)) == 1): 
        return (n, e)
    else:
        raise Exception('Improper e')
开发者ID:re-skinnybear,项目名称:NumberTheoryCrypt,代码行数:12,代码来源:finalproject.py

示例4: check_trucations

def check_trucations(n):

    number_digits = digits(n)

    for x in range(1, len(number_digits)):
        truncation1 = number_digits[x:]
        truncation2 = number_digits[:len(number_digits) - x]
        number1 = digits_to_int(truncation1)
        number2 = digits_to_int(truncation2)

        if (not sympy.isprime(number1)) or (not sympy.isprime(number2)):
            return False
    return True
开发者ID:JeremySilverTongue,项目名称:Euler,代码行数:13,代码来源:37.py

示例5: golbach_other

def golbach_other():
    i = 7
    while True:
        i = i+2
        if isprime(i):
            continue
        max_j = int(math.sqrt(i/2))
        g = False
        for j in range(1,max_j+1):
            if isprime(i - 2*j*j):
                g = True
                break
        if not g:
            return i
开发者ID:david-gang,项目名称:project_euler,代码行数:14,代码来源:ex46.py

示例6: odd_composite_gen

def odd_composite_gen():
    """infinite generator of composite numbers"""
    x = 3
    while 1:
        x += 2
        if not isprime(x):
            yield x
开发者ID:iynaix,项目名称:eulerproject,代码行数:7,代码来源:utils.py

示例7: main

def main():
    summa = 0
    for i in range(1,2000001):
        if(sp.isprime(i)):
            summa += i
            
    print summa
开发者ID:KartikKannapur,项目名称:Programming_Challenges,代码行数:7,代码来源:010.py

示例8: verifie_paire_debug

def verifie_paire_debug(A, B):
    """Version plus lente qui fait tous les tests, et affiche vrai ou faux pour chaque somme a + b."""
    if A is None or B is None:
        return False
    reponse = True
    for a in A:
        if not isprime(a):
            print("  - a = {:<6} est pas premier, ECHEC ...".format(a))
            reponse = False
        for b in B:
            if not isprime(a + b):
                print("  - a = {:<6} + b = {:<6} donnent {:<6} qui n'est pas premier, ECHEC ...".format(a, b, a + b))
                reponse = False
            else:
                print("  - a = {:<6} + b = {:<6} donnent {:<6} qui est bien premier, OK ...".format(a, b, a + b))
    return reponse
开发者ID:Naereen,项目名称:notebooks,代码行数:16,代码来源:Calcul_d_une_paire_de_des_un_peu_particuliers.py

示例9: quadResidue

def quadResidue(p):
   #Check whether p is prime and odd
    if(not sp.isprime(p)):
        return "~"
    if(p%2==0):
        return "~"
    #This are the variables storing outputs
    quadR=[]
    quadNR=[]
    #Making array S with numeral count 1 to (p-1)/2
    S=[]
    #This iss the loop process for making S when a=1
    for j in range(1,int((p-1)/2)+1):
        S.append(j)
    #This operation is required for 
    #numpy based functionalities    
    S=np.array(S) 
    #Iterating for each a less than p, greater than 1   
    for a in range(1,p):
       SNew=S*a #Makes life easy, as we can make S with any a
       SNew%=p #Left reminders
       n=0 #Count of remainders greater than p/2
       #For the count of n, so to get the power
       for i in range(len(SNew)):
           if(SNew[i]>(p/2)):
               n+=1
       #Lengndre symbol operation        
       if((-1)**n==1):
           quadR.append(a)
       else:
           quadNR.append(a)
    return[quadR,quadNR]
开发者ID:suvendubrk,项目名称:number-theory,代码行数:32,代码来源:quadraticResidue.py

示例10: solve

def solve():
	for i in range(len(digits)):
		for p in permutations(digits[i:]):
			x = int(''.join(p))
			if isprime(x):
				return x
	return -1
开发者ID:kdungs,项目名称:euler,代码行数:7,代码来源:euler_41.py

示例11: prove_factorial_divides_by_n_primes

def prove_factorial_divides_by_n_primes(n):
    ''' Always returns True because a factorial
        is divisible by the all primes below n
        by definition'''
    return all(imap(lambda x, y: x % y == 0,
                    repeat(factorial(n)),
                    [y for y in range(1, n) if isprime(y)]))
开发者ID:mhinrichs,项目名称:practice-python,代码行数:7,代码来源:functional.py

示例12: calc_some

def calc_some(p):
    if p <= 5:
        raise ValueError("p must be larger than 5")
    if not sympy.isprime(p):
        raise ValueError("specify prime. actual p = {}, ntheory.divisors = {}".format(p, ntheory.divisors(p)))
    r = reciprocal(p)
    seq = calc_recurrence_seq(p)
    d = len(seq)
    former = r[:d // 2]
    latter = r[d // 2:d]
    if d % 2 == 0:
        print('length of recurrence is even')
        print('1/{} = '.format(p), r)
        print('former = ', former)
        print('latter = ', latter)
        print('former + latter =\n', Decimal(former) + Decimal(latter))
    else:
        print('length of recurrence is not even. In fact')
        print('1/{}'.format(p), r)
        print('seq = ', seq)
        print('len(seq) = ', len(seq))
        print('But you may find something')
        if latter[0] == 9:
            print("you're lucky")
            print('former = ', former)
            print('latter = ', latter)
            print('former + latter =\n', Decimal(former) + Decimal(latter))
开发者ID:terasakisatoshi,项目名称:PythonCode,代码行数:27,代码来源:reciprocal_of_p.py

示例13: replaced_is_prime

def replaced_is_prime(n, replace):
    n = str(n)
    res = 0
    for i in range(replace, 10):
        if isprime(int(n.replace(str(replace), str(i)))):
            res += 1
    return res
开发者ID:manicmaniac,项目名称:Project_Euler,代码行数:7,代码来源:Problem51.py

示例14: main

def main():
    count = 0
    for i in range(0,1000000):
        if(sp.isprime(i)):
            count += 1
            if(count == 10001):
                print i
                break
开发者ID:KartikKannapur,项目名称:Programming_Challenges,代码行数:8,代码来源:007.py

示例15: isQuadraticResidue

def isQuadraticResidue(p, a):
    if isprime(p):
        if a ** ((p - 1) / 2) % p == 1:
            return True
        else:
            return False
    else:
        return "N not a prime"
开发者ID:prateekgulati,项目名称:numberTheory,代码行数:8,代码来源:isQuadraticResidue.py


注:本文中的sympy.isprime函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。