math.sqrt() uses standard IEEE 64-bit values. It can only calculate accurately for arguments less than ~2**53. Your value for n is larger than that. If you want exact integer square roots for large numbers, I would recommend gmpy2. Disclaimer: I maintain gmpy2. Edit: Here is an updated version of your...

A warning is printed as i compiled your code by gcc main.c -o main -Wall : main.c:51:9: attention : format ‘%lf’ expects argument of type ‘double *’, but argument 2 has type ‘int *’ [-Wformat] I was able to reproduce the heap corruption by using a size of 6. The...

You could do this by introducing a while loop inside the if block and count the power of the current prime factor and print it there itself. #include <stdio.h> int main() { int n; // Get the user input. printf( "Please enter a number.\n" ); scanf( "%d", &n ); //...

math,factorization,number-theory

You're solving the problem from the wrong end. For any number X = p1^a1 * p2^a2 * ... * pn^an // p1..pn are prime d(X) = (a1 + 1)*(a2 + 1)* ... *(an + 1) For instance 50 = 4 * 25 = 2^2 * 5^2 d(50) = (1 +...

optimization,linear-algebra,julia-lang,factorization,levenberg-marquardt

It can be a bit tricky to figure out exactly which code path is taken when your are running into code that uses substitutions during parsing as is the case for '. You could try julia> ( J'*J + sqrt(100)*DtD ) \ -J'fcur to see another substitution taking place. I...

ruby-on-rails,ruby,primes,factorization

"premature optimization is (the root of all) evil". :) Here you go right away for the (1) biggest, (2) prime, factor. How about finding all the factors, prime or not, and then taking the last (biggest) of them that is prime. When we solve that, we can start optimizing it....

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,factorization,quantum-computing

It looks like an efficient algorithm is going to be hard: From wikipedia: The problem of deciding whether a state is separable in general is sometimes called the separability problem in quantum information theory. It is considered to be a difficult problem. It has been shown to be NP-hard. Gurvits,...

Your function EfficientFactorList does a good job of efficiently grabbing the set of all factors for each number from 1 to n, so all that remains is getting the set of all factorizations. As you suggest, using the factorizations of smaller values to compute the factorizations for larger values seems...

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...

actionscript-3,flash,primes,factorization,factors

Try this : function prime_factorization( n:int ): Array { var a:Array = [] ; for (var i:int = 2; i <= n / i; i++) { while (n % i == 0) { a.push(i) ; n = n / i ; } } if (n > 1) a.push(n) ; return...