def find_solution(): res = [] for number in xrange(2, 10000): factors = factorize(number) d1 = (sum(make_divisors(factors)) - number) factors = factorize(d1) d2 = (sum(make_divisors(factors)) - d1) if d2 == number and d1 != number: res.append(number) return sum(res)
def main(): n = int(input('Введите n = ')) k = int(input('Введите k = ')) iters = int(input('Введите l = ')) factors = factorize(n, fermat, k, iters) print('\n'.join(map(str, factors.items())))
def p29(): """ To factorize (A^B), factorize A then multiply the prime powers by B. Store the factorizations and check for uniqueness """ primeList = [] prime = gen_primes() p = next(prime) while (len(primeList) < 100): primeList.append(p) p = next(prime) factorSet = [] for base in range(2, 101): for power in range(2, 101): factors = factorize(base, primeList) for i in range(len(factors)): factors[i] *= power unique = 1 for i in range(len(factorSet)): match = 1 for j in range(len(factorSet[i])): if factorSet[i][j] != factors[j]: match = 0 break if (match): unique = 0 break if (unique): factorSet.append(factors) print(len(factorSet))
def main(): if len(argv) == 1: n = int(input('Введите n = ')) c = int(input('Введите с = ')) % n assert 1 < c < n, 'c должно быть 1 < c < n' elif len(argv) == 2: n = int(argv[1]) c = int(input('Введите с = ')) % n else: n = int(argv[1]) c = int(argv[2]) % n assert 1 < c < n, 'c должно быть 1 < c < n' factors = factorize(n, p_pollard, c) print('\n'.join(map(str, factors.items())))
def find_solution(): abundant_numbers = [] res = 1 for i in xrange(2, 28124): found = False if sum(make_divisors(factorize(i))) > 2*i: abundant_numbers.append(i) for number in abundant_numbers: if i - number in abundant_numbers: found = True break if 2*number > i: break if not found: res += i return res
def toneli_shanks(a, p): # find z such as Legendre symbol (z/p) == -1 z = get_non_quad(p) q = p - 1 s, q = factorize(q) #(p-1)=2^n*k c = fast(z, q, p) r = fast(a, (q + 1) // 2, p) t = fast(a, q, p) m = s while t % p != 1: i = 1 #Find the least i such as t^2^imodp=1modp while fast(t, 2**i, p) != 1: #if i!=0 then increase until c^2^(m-i-1) = 1modp i += 1 b = fast(c, 2**(m - i - 1), p) r = r * b % p t = t * b * b % p c = b * b % p m = i return r, p - r #solutions
def test_8(self): self.assertEqual(prime.factorize(8), [2,2,2])
def test_2(self): self.assertEqual(prime.factorize(2), [2])
def test_2342623178(self): self.assertEqual(prime.factorize(2342623178), [2,7,1237,135271])
def test_4126264356(self): self.assertEqual(prime.factorize(4126264356), [2,2,3,59,5828057])
def test_34503489(self): self.assertEqual(prime.factorize(34503489), [3,3,3,3,17,25057])
def test_empty(self): self.assertEqual(prime.factorize(1), [])
def prime_time(n): print('Factorizing', n) start = time.clock() print(prime.factorize(n)) stop = time.clock() - start print('Factorization took {:.2f} seconds.'.format(stop))
def test_100(self): self.assertEqual(prime.factorize(100), [2,2,5,5])
def test_3(self): self.assertEqual(prime.factorize(3), [3])
def test_7(self): self.assertEqual(prime.factorize(7), [7])
def test_6(self): self.assertEqual(prime.factorize(6), [2,3])
def test_5(self): self.assertEqual(prime.factorize(5), [5])
def test_4(self): self.assertEqual(prime.factorize(4), [2,2])
def number_of_divisors_less(number, limit): factors = factorize(number) if 2**len(factors) < limit: return True return len(make_divisors(factors)) < limit
def test_9(self): self.assertEqual(prime.factorize(9), [3,3])