Ejemplo n.º 1
0
def get_divisors(n):
    pfs = prime_factors.prime_factors(n)
    pfs.sort()
    dvs = divisors(pfs)
    dvs.extend([1, n])

    return dvs
Ejemplo n.º 2
0
 def test_product_of_primes_and_non_primes(self):
     self.assertEqual(prime_factors(6), [2, 3])
     self.assertEqual(prime_factors(12), [2, 2, 3])
     self.assertEqual(prime_factors(147), [3, 7, 7])
     self.assertEqual(prime_factors(330), [2, 3, 5, 11])
     self.assertEqual(prime_factors(343), [7, 7, 7])
     self.assertEqual(prime_factors(552), [2, 2, 2, 3, 23])
     self.assertEqual(prime_factors(32767), [7, 31, 151])
     self.assertEqual(prime_factors(48), [2, 2, 2, 2, 3])
Ejemplo n.º 3
0
def prime_factor_count(given):
    count = {}
    factors = prime_factors(given)
    for f in factors:
        if f in count:
            count[f] += 1
        else:
            count[f] = 1
    return count
Ejemplo n.º 4
0
def totient(n):
    if n < 0:
        n = n * -1

    elif n is 1:
        return n
	
    tnt = n
    primeFactors = []
    prime_factors(n, primeFactors)
     
    #totient function is the product of (1-pn)(1-p(n-1))...(1-p(1)) times 
    for i in primeFactors:
        pf = Decimal(1 / Decimal(i))
        a = Decimal(1 - pf)
        tnt = Decimal(tnt * a)

    return int(tnt)
Ejemplo n.º 5
0
 def decompose_argument(self, n):
     self.results_table.setItem(self.row_counter, 0, QTableWidgetItem(str(n)))
     prime_handler = prime_factors()
     prime_handler.decompose(n)
     factor_string = ''
     for i in range(len(prime_handler.factors)):
         factor_string += str(prime_handler.factors[i])
         factor_string += ", "
     factor_string = factor_string[:len(factor_string)-2]
     self.results_table.setItem(self.row_counter, 1, QTableWidgetItem(factor_string))
     self.row_counter+=1
Ejemplo n.º 6
0
 def decompose(self):
     user_input = self.input_line_edit.text()
     self.results_table.setItem(self.row_counter, 0, QTableWidgetItem(user_input))
     prime_handler = prime_factors()
     prime_handler.decompose(int(user_input))
     factor_string = ''
     for i in range(len(prime_handler.factors)):
         factor_string += str(prime_handler.factors[i])
         factor_string += ", "
     factor_string = factor_string[:len(factor_string)-2]
     self.results_table.setItem(self.row_counter, 1, QTableWidgetItem(factor_string))
     self.row_counter+=1
Ejemplo n.º 7
0
def main():
    input_number = np.arange(1, 1001, 1)
    decomp_data = []
    for i in input_number:
        print("---------------------------")
        print(i, "inputs")
        generator1 = generator(i)
        start_time = time.clock()
        prime1 = prime_factors()
        end_time = time.clock()
        print("decomposer finised in {} ms".format(
            (end_time - start_time) * 1000))
        decomp_data.append((end_time - start_time) * 1000)
        print("---------------------------\n")

    with open("data/decomp_data.csv", 'w') as WRITE_FILE:
        WRITE_FILE.write('number of inputs, runtime (in ms)\n\n')
        for i in input_number:
            WRITE_FILE.write(str(i) + ", " + str(decomp_data[i - 1]) + "\n")
    WRITE_FILE.close()
Ejemplo n.º 8
0
def factors(n):

    list_1 = []
    count = 0
    for i in range(n - 1, 1, -1):
        if count >= 100:
            break
        if miller_rabin(i) is True:  # if the num if prime
            new_list = [i + 1]  # ck = pk + 1
            list_1.append(new_list)
            count += 1

    for i in range(len(list_1)):
        prime_factor_list = prime_factors(list_1[i][0])
        for j in range(len(prime_factor_list)
                       ):  # finds all the prime factors of the given number
            list_1[i].append(prime_factor_list[j])
    main_list = []

    for i in range(len(list_1) - 1, -1, -1):
        main_list.append(list_1[i])

    return main_list
 def test_factors_of_one(self):
     self.assertEqual([], prime_factors(1))
Ejemplo n.º 10
0
 def test_product_of_primes_and_non_primes(self):
     self.assertEqual(prime_factors(12), [2, 2, 3])
 def test_factors_of_nine(self):
     self.assertEqual([3, 3], prime_factors(9))
 def test_factors_of_seventeen(self):
     self.assertEqual([17], prime_factors(17))
Ejemplo n.º 13
0
 def test_factoring_prime_times_prime_returns_prime_and_prime(self, prime):
     self.assertEqual([prime, prime], prime_factors(prime * prime))
 def test_factors_of_four(self):
     self.assertEqual([2, 2], prime_factors(4))
Ejemplo n.º 15
0
def is_smith_number(n):
    sum_factor_digits = sum(sum_digits(f) for f in prime_factors(n))
    return sum_factor_digits == sum_digits(n)
Ejemplo n.º 16
0
 def test_a_primes_only_prime_factor_is_itself(self, prime):
     self.assertEqual([prime], prime_factors(prime))
Ejemplo n.º 17
0
 def test_zero(self):
     with self.assertRaisesWithMessage(ValueError):
         prime_factors(0)
Ejemplo n.º 18
0
 def test_prime_number(self):
     self.assertEqual(prime_factors(2), [2])
Ejemplo n.º 19
0
 def test_product_of_primes(self):
     self.assertEqual(prime_factors(901255), [5, 17, 23, 461])
Ejemplo n.º 20
0
 def test_cube_of_a_prime(self):
     self.assertEqual(prime_factors(8), [2, 2, 2])
Ejemplo n.º 21
0
 def test_square_of_a_prime(self):
     self.assertEqual(prime_factors(9), [3, 3])
Ejemplo n.º 22
0
 def test_square_of_a_prime(self):
     self.assertEqual(prime_factors(9), [3, 3])
Ejemplo n.º 23
0
 def test_product_of_primes(self):
     self.assertEqual(prime_factors(901255), [5, 17, 23, 461])
Ejemplo n.º 24
0
 def test_factors_include_a_large_prime(self):
     self.assertEqual(prime_factors(93819012551), [11, 9539, 894119])
Ejemplo n.º 25
0
 def test_no_factors(self):
     self.assertEqual(prime_factors(1), [])
Ejemplo n.º 26
0
 def test_invalid_input(self):
     with self.assertRaisesWithMessage(ValueError):
         prime_factors(-1)
Ejemplo n.º 27
0
 def test_3(self):
     self.assertEqual([3], prime_factors(3))
Ejemplo n.º 28
0
 def test_factors_include_a_large_prime(self):
     self.assertEqual(prime_factors(93819012551), [11, 9539, 894119])
Ejemplo n.º 29
0
 def test_4(self):
     self.assertEqual([2, 2], prime_factors(4))
Ejemplo n.º 30
0
 def test_factoring_two_times_prime_returns_two_and_prime(self, prime):
     self.assertEqual([2, prime], prime_factors(2 * prime))
Ejemplo n.º 31
0
 def test_6(self):
     self.assertEqual([2, 3], prime_factors(6))
Ejemplo n.º 32
0
 def test_factoring_product_of_primes_returns_all_primes(self, primes):
     some_big_number = reduce(lambda a, b: a * b, primes)
     self.assertEqual(sorted(primes), sorted(prime_factors(some_big_number)))
Ejemplo n.º 33
0
 def test_8(self):
     self.assertEqual([2, 2, 2], prime_factors(8))
 def test_factors_of_eight(self):
     self.assertEqual([2, 2, 2], prime_factors(8))
Ejemplo n.º 35
0
 def test_9(self):
     self.assertEqual([3, 3], prime_factors(9))
 def test_factors_of_thirty(self):
     self.assertEqual([2, 3, 5], prime_factors(30))
Ejemplo n.º 37
0
 def test_27(self):
     self.assertEqual([3, 3, 3], prime_factors(27))
 def test_factors_of_some_big_number(self):
     primes = [2, 2, 2, 3, 5, 7, 7, 11, 13]
     some_big_number = reduce(lambda a, b: a * b, primes)
     self.assertEqual(primes, prime_factors(some_big_number))
Ejemplo n.º 39
0
 def test_625(self):
     self.assertEqual([5, 5, 5, 5], prime_factors(625))
 def test_factors_of_two(self):
     self.assertEqual([2], prime_factors(2))
Ejemplo n.º 41
0
 def test_901255(self):
     self.assertEqual([5, 17, 23, 461], prime_factors(901255))
Ejemplo n.º 42
0
 def test_product_of_primes_and_non_primes(self):
     self.assertEqual(prime_factors(12), [2, 2, 3])
 def test_93819012551(self):
     self.assertEqual([11, 9539, 894119], prime_factors(93819012551))
Ejemplo n.º 44
0
 def test_prime_number(self):
     self.assertEqual(prime_factors(2), [2])
     self.assertEqual(prime_factors(13), [13])
 def test_1(self):
     self.assertEqual([], prime_factors(1))
Ejemplo n.º 46
0
 def test_cube_of_a_prime(self):
     self.assertEqual(prime_factors(8), [2, 2, 2])
 def test_2(self):
     self.assertEqual([2], prime_factors(2))
Ejemplo n.º 48
0
 def test_no_factors(self):
     self.assertEqual(prime_factors(1), [])
Ejemplo n.º 49
0
#!/usr/bin/python

import sys
from prime_factors import prime_factors

primeFactors = prime_factors(int(sys.argv[1]))
primeFactors.sort(key=int)
print ", ".join(primeFactors)