コード例 #1
0
 def test_is_prime(self):
     print('is_prime')
     self.assertTrue(is_prime(5))
     self.assertFalse(is_prime(8))
     self.assertFalse(is_prime(0))
     self.assertFalse(is_prime(-1))
     self.assertFalse(is_prime(-3))
コード例 #2
0
ファイル: problem037.py プロジェクト: tomemelko/project-euler
from myfunc import is_prime

sum = 0
count = 0
for n in range(9,1000000):
  trunc = True
  i = n
  if count == 11:
    break
  while len(str(i)) != 0:
    if not is_prime(i):
      trunc = False
      break
    if len(str(i)) == 1:
      break
    i = int(str(i)[1:])
  i = n
  while len(str(i)) != 0:
    if not is_prime(i):
      trunc = False
      break
    if len(str(i)) == 1:
      break
    i = int(str(i)[:-1])
                              
  if trunc:
    print n
    sum += n
    count += 1
print sum
print count
コード例 #3
0
ファイル: problem003.py プロジェクト: tomemelko/project-euler
import math
from myfunc import is_prime

n = 600851475143
for i in range(3,int(math.sqrt(n)),2):
  if (n % i == 0):
    if (is_prime(i)):
      print i
コード例 #4
0
ファイル: problem041.py プロジェクト: tomemelko/project-euler
from myfunc import is_prime
from itertools import permutations
max = 0
#Since all 9-pandigital numbers will sum to 45, and therefore are divisible by 3
#And the samething goes for 8 digit pandigital numbers, as they sum to 36
#We only need to go up to 7 digits
for i in permutations(['1','2','3','4','5','6','7']):
  num = ''.join(i)
  if (is_prime(int(num))):
    if (num > max):
      max = num
print max
コード例 #5
0
ファイル: problem027.py プロジェクト: tomemelko/project-euler
from myfunc import is_prime, prime_list

bestcount = 0
bestproduct = 0
for n in xrange(0,200):
  print "n=",n
  for a in xrange(-1000,1000):
    count = 0
    for b in prime_list(1000):
      if (((n**2)+(a*n)+b) > 0):
        if (is_prime((n**2)+(a*n)+b)):
          count += 1
    if (count > bestcount):
      bestcount, bestproduct = count, a*b
print bestproduct
コード例 #6
0
 def test_is_prime(self):
     print("测试is_prime方法")
     #测试用例以test_开头;使用unittest提供的断言方法;
     self.assertTrue(is_prime(5))
     self.assertTrue(is_prime(5))
コード例 #7
0
ファイル: problem035.py プロジェクト: tomemelko/project-euler
import myfunc

count = 0
for i in myfunc.prime_list():
  if i > 1000000:
    break
  tmp = myfunc.shift_digits(str(i), 1)
  circ = True
  while int(tmp) != i:
    if not myfunc.is_prime(int(tmp)):
      circ = False
    tmp = myfunc.shift_digits(tmp, 1)
  if circ:
    count += 1
print count