prime-factoring

Algorithm: Factorize a integer X to get as many distinct positive integers(Y1…Yk) as possible so that (Y1+1)(Y2+1)…(Yk+1) = X

99封情书 提交于 2021-01-28 13:00:33
问题 I recently met a algorithm question in open.kattis.com. The question's link is https://open.kattis.com/problems/listgame2. Basically, it is a question ask the players to factorize a integer X (10^3 <= X <= 10^15) to get as many distinct positive integers (Y 1 ,...,Y k ) as possible such that (Y 1 +1)(Y 2 +1)⋯(Y k +1) = X. I already came up with a solution using Python3, which does pass several test cases but failed one of them:MyStatus My code is: def minFactor(n, start): maxFactor = round(n*

Fast Algorithm to Factorize All Numbers Up to a Given Number

[亡魂溺海] 提交于 2021-01-27 13:19:25
问题 I am looking for an algorithm that could factorize numbers based on numbers it already factorized. In other words, I am searching for a fast algorithm to factorise all numbers up to a given number, and store them in a (I guess this is the easiest data structure to use) list / tuple of tuples. I am looking for an "up to n" algorithm because I need all numbers up to "n", and I guess it's faster than just checking one by one. I want this algorithm to work within a reasonable time (less than an

Fast Prime Factorization Algorithm

落爺英雄遲暮 提交于 2020-12-29 04:19:33
问题 I'm writing a code in C that returns the number of times a positive integer can be expressed as sums of perfect squares of two positive integers. R(n) is the number of couples (x,y) such that x² + y² = n where x, y, n are all non negative integers. To compute R(n), I need to first find the prime factorization of n. The problem is that I've tried a lot of algorithm for prime factorization that I can use on C but I need my code to be as fast as possible, so I would appreciate it if anyone can

Fast Prime Factorization Algorithm

孤者浪人 提交于 2020-12-29 04:17:30
问题 I'm writing a code in C that returns the number of times a positive integer can be expressed as sums of perfect squares of two positive integers. R(n) is the number of couples (x,y) such that x² + y² = n where x, y, n are all non negative integers. To compute R(n), I need to first find the prime factorization of n. The problem is that I've tried a lot of algorithm for prime factorization that I can use on C but I need my code to be as fast as possible, so I would appreciate it if anyone can

Fast Prime Factorization Algorithm

那年仲夏 提交于 2020-12-29 04:16:10
问题 I'm writing a code in C that returns the number of times a positive integer can be expressed as sums of perfect squares of two positive integers. R(n) is the number of couples (x,y) such that x² + y² = n where x, y, n are all non negative integers. To compute R(n), I need to first find the prime factorization of n. The problem is that I've tried a lot of algorithm for prime factorization that I can use on C but I need my code to be as fast as possible, so I would appreciate it if anyone can

How to find Number of Factors of “product of numbers”

只愿长相守 提交于 2020-07-17 08:54:51
问题 I m trying to find number of factors of product of big numbers. The problem statement is this : Suppose you are given N numbers(let say N = 10), each number <= 1000000. How to find the number of factors of the product of such numbers. Can someone please provide an efficient algorithm for doing this. Example : 1) N = 3 and Numbers are 3, 5, 7 Ans = 8 (1, 3, 5, 7, 15, 21, 35, 105) 2) N = 2 and Numbers are 5, 5 Ans = 3 (1, 5 and 25) 回答1: Editorial for the problem is here http://discuss.codechef

Better way to find all the prime factors of huge integers in C?

前提是你 提交于 2020-07-10 08:25:10
问题 I have written a code in C that basically makes a list of all the prime factors of a huge number, which is stored using the gmp library. Here it is : int is_div(mpz_t number, mpz_t i) { return mpz_divisible_p(number,i)!=0; } mpz_t * prime_divs(mpz_t number){ mpz_t * prime_dividers = NULL; mpz_t i, i_squared,TWO, comp; mpz_inits(i, i_squared, TWO, comp, NULL); mpz_set_ui(i,2); mpz_mul(i_squared, i ,TWO); while(mpz_cmp(i_squared,number)<=0){ if(is_div(number,i)){ mpz_fdiv_q(comp, number, i); if

Prime factorization of a number

家住魔仙堡 提交于 2020-03-02 09:28:47
问题 I'm trying to write a program to find all the prime factors of a given number, and tried the following: def factors(nr): i = 2 factors = [] while i<nr: if (nr%i)==0: factors.append(i) nr = nr/i else: i = i+1 return factors My idea is the following. Start with i = 2, while i < the number, check if the module of the number and i = 0. If this is the case, add i to a list, and run the algorithm again, but now with the new number. However, my algorithm doesn't work. Any idea why? I know that