コード例 #1
0
ファイル: euler_37.py プロジェクト: krishnanj/euler_projects
def is_sub_prime(n):
	tf = True
	for i in range(1, len(str(n))):
		n_sub =  int(str(n)[:-i])
		tf = isp.is_prime(n_sub) and tf
	if(tf):
		tf2 = True
		for j in range(1, len(str(n))):
			tf2 = isp.is_prime(int(str(n)[j:])) and tf2
	if(tf and tf2):
		return n
	else:
		return 0
コード例 #2
0
def prime_number_of_divisors(n):
    count = 0

    for i in range(1, n+1):
        if n % i == 0:
            count += 1
    return is_prime(count)
コード例 #3
0
ファイル: end.py プロジェクト: jesee030/pythonProject
def prime_palindrome(num):
    """
        判断一个数是不是回文素数
        :param num: 正整数
        :return: 是回文素数返回True,不是回文素数返回False
        """
    #        请在此处添加代码       #
    # *************begin************#
    if (is_palindrome(num) and is_prime(num)):
        return True
    return False
コード例 #4
0
def prime_number_of_divisors(n):
    list_of_divisors = [n]

    for i in range(1, n):
        if n % i == 0:
            list_of_divisors.append(i)

    #print(list_of_divisors)
    #print(len(list_of_divisors))
    if is_prime(len(list_of_divisors)):
        return True
    else:
        return False
コード例 #5
0
def prime_number_of_divisors(n):
    list_of_divisors = [n] 
    
    for i in range(1,n):
        if n % i == 0:
            list_of_divisors.append(i)
    
    #print(list_of_divisors)
    #print(len(list_of_divisors))
    if is_prime(len(list_of_divisors)):
        return True
    else:
        return False
コード例 #6
0
def generate_primes_aux(k_min, k_max, p_max, npick):
    assert npick > 0
    for k in range(k_min, k_max + 1):
        c_start = p_max >> k
        if c_start % 2 == 0:
            c_start -= 1
        while c_start % 3 != 0:
            c_start -= 2
        nleft = npick
        for c in range(c_start, -3, -6):
            p = (c << k) + 1
            if is_prime(p):
                yield p
                nleft -= 1
                if not nleft:
                    break
コード例 #7
0
__author__ = "Ajay Rangarajan, Jeyashree Krishnan"
__email__ = "rangarajan, [email protected]"


import numpy as np 
import isprime as isp

max_a = 0
max_b = 0
max_n = 0
for a in range(-999,1000):
	for b in range(-1001,1001):
		n=0
		p = 5
		while ((p>0) and isp.is_prime(p)==True):
			n = n + 1
			p = n**2 + a*n + b
		if(n>max_n):
			max_n = n
			max_a = a
			max_b = b
print max_a * max_b
"""
Euler discovered the remarkable quadratic formula:

n2+n+41n2+n+41
It turns out that the formula will produce 40 primes for the consecutive integer values 0≤n≤390≤n≤39. However, when n=40,402+40+41=40(40+1)+41n=40,402+40+41=40(40+1)+41 is divisible by 41, and certainly when n=41,412+41+41n=41,412+41+41 is clearly divisible by 41.

The incredible formula n2−79n+1601n2−79n+1601 was discovered, which produces 80 primes for the consecutive values 0≤n≤790≤n≤79. The product of the coefficients, −79 and 1601, is −126479.
コード例 #8
0
__author__ = "Ajay Rangarajan, Jeyashree Krishnan"
__email__ = "rangarajan, [email protected]"

import numpy as np
import isprime as isp


## find if a given number is pandigital
def is_pandigital(n):
    d = len(str(n))
    sort = "".join(sorted(str(n)))
    if (d > 9):
        print 'error'
        return 0
    else:
        val = ''
        for i in range(1, d + 1):
            val = val + str(i)
        if (sort == val):
            return n
        else:
            return 0


maxval = 90000000
for i in np.arange(maxval, 0, -1):
    # print 'Entered here!'
    if (is_pandigital(i)):
        if (isp.is_prime(i)):
            print i
            break
コード例 #9
0
ファイル: solution.py プロジェクト: mbreyt/hackinscience
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 24 15:42:33 2015

@author: mbreyt
"""

import isprime
total = 0
for i in range(1, 1001):
    if isprime.is_prime(i):
        total += i
print(total)
コード例 #10
0
ファイル: euler_37.py プロジェクト: krishnanj/euler_projects
from decimal import *
import itertools
import isprime as isp

def is_sub_prime(n):
	tf = True
	for i in range(1, len(str(n))):
		n_sub =  int(str(n)[:-i])
		tf = isp.is_prime(n_sub) and tf
	if(tf):
		tf2 = True
		for j in range(1, len(str(n))):
			tf2 = isp.is_prime(int(str(n)[j:])) and tf2
	if(tf and tf2):
		return n
	else:
		return 0

k = 0
n = 10
ans = 0
while(k<12):
	if(isp.is_prime(n)):
		if(is_sub_prime(n)):
			k = k+1
			print is_sub_prime(n)
		ans = ans + is_sub_prime(n)
	n = n + 1
print ans

コード例 #11
0
        string = ''
        for j in p:
            string = string + j
        out.append(string)
    return out


def digit(n):
    digit_str = []
    string = str(n)
    for val in string:
        digit_str.append(val)
    return digit_str


count = 0
for n in range(1, 1000001):
    str_digit = digit(n)
    nums = longestWord(str_digit)
    tf = True
    for i in range(0, len(nums)):
        tf = isp.is_prime(int(nums[i])) and tf

    if (tf == True):
        count = count + 1
        print nums, ' is circular prime'
print count
# a = list(itertools.permutations(str_digit, len(str_digit)))
# for i in range(0, len(a)):
# print a[1][1]
コード例 #12
0
ファイル: euler_46.py プロジェクト: krishnanj/euler_projects
def is_perfect_sqaure(n):
    if (np.floor(n) == n):
        return True
    else:
        return False


# initialize counter for non-convergence of Goldbach's Conjecture
k = 1
search = True
while (search == True):
    # initialize starting odd number
    odd_no = 2 * k + 1

    # Check if the generated odd number is composite. If not increment 'k'
    if (isp.is_prime(odd_no) == False):
        # 'odd_no' is composite
        tf = []
        # Generate all odd numbers below the given odd composite number
        for i in range(1, k):
            prime = 2 * i + 1
            # selected_prime = 0
            # selected_square = 0
            # Check if these odd numbers are prime
            if (isp.is_prime(prime)):
                # calculate difference between the odd number and any prime number less that itself
                diff = odd_no - prime
                sq_no = np.sqrt(diff / 2.0)
                tf.append(is_perfect_sqaure(sq_no))
                if (is_perfect_sqaure(sq_no)):
                    selected_prime = prime  # Select the number for which we have a solution to Goldbach's conjectures
コード例 #13
0
from isprime import is_prime
x = int(input())
print(is_prime(x))
コード例 #14
0
ファイル: test_isprime.py プロジェクト: fjpalacios/exercises
def test_is_prime(result, expected):
    _ip = isprime.is_prime(result)
    assert _ip == expected