Example #1
0
def primes(n):

  # 1
  if number.integralPower(n):
    return 0

  # 2
  r = 2

  # 3
  while r < n:

    # 4
    if number.gcd(n, r) != 1:
      return 0

    # 5
    if r in number.SMALL_PRIMES:

      # 6
      factors = number.factor(r - 1)
      if len(factors) == 0:
        q = 0 # hack
      else:
        q = factors[-1]

      # 7
      if (q >= 4 * math.sqrt(r) * number.lg(n)) and (number.modPow(n, (r - 1) / q, r) != 1):

        # 8
        break

    # 9
    r = r + 1

  # 10

  print "r for ", n, ":", r
  return r

  # 11
  #for a in range(1, int(2 * math.sqrt(r) * number.lg(n)) + 2)):

    # 12
    #poly = [-1] + [0] * (r - 1) + [1]
    #lhs = polynomial.modPow([-a, 1], n, poly)
    #rhs = polynomial.mod([-a] + [0] * (n - 1) + [1], poly)
    #if lhs != rhs:
    #  return 0

  # 13
  return 1
Example #2
0
 def testGcd(self):
   self.assertRaises(number.NegativeNumberNotAllowedException, number.gcd, 1, -1);
   self.assertRaises(number.NegativeNumberNotAllowedException, number.gcd, -1, 1);
   self.assertEquals(0, number.gcd(0, 1))
   self.assertEquals(0, number.gcd(0, 1))
   self.assertEquals(3, number.gcd(27, 15))
   self.assertEquals(3, number.gcd(15, 27))
   self.assertEquals(1, number.gcd(27, 16))
   self.assertEquals(1, number.gcd(16, 27))
Example #3
0
import fibo
import health
import number

fibo.fib(10)
print(fibo.fib2(10))
print(health.bmi(170, 52))
print(number.gcd(42, 75))
print(number.lcd(42, 75))
Example #4
0
 def _get_e(self):
     while True:
         n = random.randint(2, 255)
         if number.gcd(n, self._phi) == 1:
             return n