java,algorithm,prime-factoring

In your case, a! / b! is 3,124,993,750,004,374,998,750,000,120,000,000 which is somewhat larger than 2^111. Only numbers up to 2^53 can be safely represented as an integer with a double value. If you use long, you can crank that up to 2^63, which still isn't enough. You must either use BigInteger...

arrays,algorithm,prime-factoring,number-theory

This problem can be solved by finding a maximum matching in the following graph. For each array value x, for each prime factor of x with multiplicity, make a new vertex. If x = 12, for example, then we create two 2 vertices and one 3 vertex. Make edges between...

python,recursion,prime-factoring

your code is fine except for this : lst.append(primeFac(n//c)) return lst you append the return, and return a list, so you will append a list to your list, on the "normal" iteration you used : lst.append(c) so you was appending just the value. you can do like this to concatenate...

First, there is an implicit "when" (or "if") in the test part of any cond so you should not be using when yourself inside that test. Second, you are using a single form, a when form, as the entire branch of the cond, therefore, the cond does not see the...

python,algorithm,primes,prime-factoring

Here's one way: def largest_primes_under(number, cap): n = cap - 1 while number and n >= 2: if all(n % d for d in range(2, int(n ** 0.5 + 1))): yield n number -= 1 n -= 1 Demo: for p in largest_primes_under(10, 10**9): print(p) Output: 999999937 999999929 999999893 999999883...

python,algorithm,python-3.x,prime-factoring

You can speed things up by dividing n by the obtained value in each iteration step. This way you decrease the number you are iterating. I would implement something like this (not yet sure if this is optimal and results in the lowest number of operations): from math import sqrt...

android,algorithm,prime-factoring

Your pollard function is okay but not great. You are using Pollard's original algorithm, but it would be better to use Brent's variant. But that's probably not the source of your slow performance. Your trial division function is slow. Checking each possible divisor for primality is very expensive, and not...

Line 116 : A loop is endless. for(unsigned int j = 0; i < sizeof(result)-1; j++) i never changes in the inner loop where j is increasing, thus preventing your program from advancing further and printing anything....

math,proof,prime-factoring,number-theory

Initially the process proceeds to search for the smallest factor of n smaller than its square root. If it doesn't have one, then n is prime. So print out n as it's one smallest prime factor! If you find a smallest factor then it must be prime. If not, it's...

security,certificate,primes,prime-factoring

As noted in my comment, RSA keys are usually way larger in size. Your examples can be brute forced easily (!). RSA keys as used for SSH and similar are usually 2048 or even 4096 bit long (approx 616 resp. 1233 decimal digits). At that point, trying to brute-force them...

c#,math,primes,prime-factoring

I think, by the nature of the algorithm, there's no direct way to check if N is prime. To check if N is prime, first, you can use the easy divisors (2, 5, 7, etc), then you can generates all the Atkin primes under N, and then try to divide...

java,algorithm,recursion,primes,prime-factoring

You can add f as an argument by overloading, and adding private method that does take it, and is invoked from the "main" public method. In the private method, you have 3 cases: stop clause: n==1: create a new empty list n%f == 0: recurse with n'=n/f, f'=f, and add...

python,primes,prime-factoring,factorization

From your approach you are first generating all divisors of a number n in O(n) then you test which of these divisors is prime in another O(n) number of calls of test_prime (which is exponential anyway). A better approach is to observe that once you found out a divisor of...

algorithm,primes,prime-factoring

To show that I can generate a list of the first J primes in time polynomial in J, I need to work out the cost of however I am generating the list. If I am generating the list by checking numbers one after the other and discarding non-primes, there are...

ruby,algorithm,primes,prime-factoring,factorization

You need to break the $primes.each loop as soon as you find a factor, or it'll complete the loop each time. while !($primes.include?(num)) $primes.each do |x| if num % x == 0 then $factors.push(x) num /= x break end end end $factors.push(num) P.S: I've just kept to the algorithmic side...

The problems with your code are that you're repeatedly doing some expensive computation in the call functools.reduce(operator.mul, factorlist, 1) and that you're repeatedly checking isprime(x) for the same numbers (and isprime is itself expensive because of the loop). To avoid the functools.reduce call you can simply divide out the already...

python,python-3.x,for-loop,prime-factoring

You can break and use else: n = int(input("Enter a number: ")) for i in range(2, n): if n % i == 0: print(False) break else: print(True) True will only be printed if the loop completes fully i.e no n % i was equal to 0....

c++,optimization,prime-factoring

Your proposed algorithm is, as you imply, horribly inefficient. But for the stated range, this is a very simple problem for computers with 32-bit integer arithmetic. This is how to do it: for (int p = 2 ; p * p <= n ; p = (p == 2) ?...

using sieve of eratosthenes to first generate list of primes: from math import sqrt def sieve_of_eratosthenes(n): primes = range(3, n + 1, 2) # primes above 2 must be odd so start at three and increase by 2 for base in xrange(len(primes)): if primes[base] is None: continue if primes[base] >=...

Your hypothesis is correct. A real number data type in TI-Basic can only store up to 44 bits of data (source). This can be proved by using the solve( command in the following way: solve((X+1)-X,X,0 Whether run as a program, called as a subprogram, or executed from the home screen,...

c++,segmentation-fault,prime-factoring

You don't need to do all that work; in particular, you don't need to allocate all that memory. Here's a simple algorithm that will quickly factor integers of modest size, including that of Project Euler 3: function factors(n) f := 2 while f * f <= n while n %...

Your primality test function is horrible. Quick win: count forwards not backwards. Currently you'll count through at lease half your number until you find a factor! That probably accounts for the delay you are observing. Bit better: count odd numbers up to the square root. Perhaps better still: count prime...