def testFactorizeSmall(self): for n in xrange(1, 100025): a = list(intalg.yield_slow_factorize(n)) b = intalg.finder_slow_factorize(n) c = intalg.factorize(n, divisor_finder=intalg.brent) d = intalg.factorize(n, divisor_finder=intalg.pollard) assert a == b == c == d, (n, a, b, c, d)
def testFactorizeMedium(self): n = intalg.next_prime(intalg._SMALL_PRIME_LIMIT) ** 2 - 10 limit = n + 20025 while n < limit: # xrange can't take a long (n). a = list(intalg.yield_slow_factorize(n)) b = intalg.finder_slow_factorize(n) c = intalg.factorize(n) c = intalg.factorize(n, divisor_finder=intalg.brent) d = intalg.factorize(n, divisor_finder=intalg.pollard) assert a == b == c == d, (n, a, b, c, d) n += 1
def testFactorizeMedium(self): n = intalg.next_prime(intalg._SMALL_PRIME_LIMIT)**2 - 10 limit = n + 20025 while n < limit: # xrange can't take a long (n). a = list(intalg.yield_slow_factorize(n)) b = intalg.finder_slow_factorize(n) c = intalg.factorize(n) c = intalg.factorize(n, divisor_finder=intalg.brent) d = intalg.factorize(n, divisor_finder=intalg.pollard) assert a == b == c == d, (n, a, b, c, d) n += 1
def testFactorizeLargePrimes(self): random_obj = intalg.MiniIntRandom(42) for ps in ([1073741827, 1152921504606847009], [34359738421, 1180591620717411303449], [7, 1763668414462081], [100003], [10000000019], [1000000000039], # Slow but tolerable. [10000000019] * 9, [1000000007] * 10, [1000000007] + [1000000009] * 2 + [1000000021] * 3): n = 1 for p in ps: n *= p divisors = set() # All divisors based on ps, except for 1. for i in xrange(1, 1 << len(ps)): r = 1 for j in xrange(0, len(ps)): if i & (1 << j): r *= ps[j] divisors.add(r) r = intalg.brent(n, random_obj) assert r in divisors r = intalg.pollard(n, random_obj) assert r in divisors sps = intalg.finder_slow_factorize(n) assert sps == ps, (n, sps, ps) sps = intalg.factorize(n) assert sps == ps, (n, sps, ps)
def testFactorizeLargePrimes(self): random_obj = intalg.MiniIntRandom(42) for ps in ( [1073741827, 1152921504606847009], [34359738421, 1180591620717411303449], [7, 1763668414462081], [100003], [10000000019], [1000000000039], # Slow but tolerable. [10000000019] * 9, [1000000007] * 10, [1000000007] + [1000000009] * 2 + [1000000021] * 3): n = 1 for p in ps: n *= p divisors = set() # All divisors based on ps, except for 1. for i in xrange(1, 1 << len(ps)): r = 1 for j in xrange(0, len(ps)): if i & (1 << j): r *= ps[j] divisors.add(r) r = intalg.brent(n, random_obj) assert r in divisors r = intalg.pollard(n, random_obj) assert r in divisors sps = intalg.finder_slow_factorize(n) assert sps == ps, (n, sps, ps) sps = intalg.factorize(n) assert sps == ps, (n, sps, ps)
def testDivisorSum(self): expected = [ 1, 3, 4, 7, 6, 12, 8, 15, 13, 18, 12, 28, 14, 24, 24, 31, 18, 39, 20, 42, 32, 36, 24, 60, 31, 42, 40, 56, 30, 72, 32, 63, 48, 54, 48, 91, 38, 60, 56, 90, 42, 96, 44, 84, 78, 72, 48, 124, 57, 93, 72, 98, 54, 120, 72, 120, 80, 90, 60, 168, 62, 96, 104, 127, 84, 144, 68, 126, 96, 144, 72, 195, 74, 114, 124, 140, 96, 168, 80, 186, 121, 126, 84, 224, 108, 132, 120, 180, 90, 234, 112, 168, 128, 144, 120, 252, 98, 171, 156, 217] self.assertEquals([intalg.divisor_sum(i) for i in xrange(1, 101)], expected) self.assertEquals([intalg.divisor_sum(intalg.factorize(i)) for i in xrange(1, 101)], expected)
def testDivisorSum(self): expected = [ 1, 3, 4, 7, 6, 12, 8, 15, 13, 18, 12, 28, 14, 24, 24, 31, 18, 39, 20, 42, 32, 36, 24, 60, 31, 42, 40, 56, 30, 72, 32, 63, 48, 54, 48, 91, 38, 60, 56, 90, 42, 96, 44, 84, 78, 72, 48, 124, 57, 93, 72, 98, 54, 120, 72, 120, 80, 90, 60, 168, 62, 96, 104, 127, 84, 144, 68, 126, 96, 144, 72, 195, 74, 114, 124, 140, 96, 168, 80, 186, 121, 126, 84, 224, 108, 132, 120, 180, 90, 234, 112, 168, 128, 144, 120, 252, 98, 171, 156, 217 ] self.assertEquals([intalg.divisor_sum(i) for i in xrange(1, 101)], expected) self.assertEquals( [intalg.divisor_sum(intalg.factorize(i)) for i in xrange(1, 101)], expected)
def testYieldFactorizeUpto(self): self.assertEquals(sorted(list(intalg.yield_factorize_upto(100))), [(i, intalg.factorize(i)) for i in xrange(1, 101)])