factorization

Why is this Haskell code snippet not infinitely recursive?

妖精的绣舞 提交于 2019-12-05 00:27:29
To help me learn Haskell, I am working through the problems on Project Euler. After solving each problem, I check my solution against the Haskell wiki in an attempt to learn better coding practices. Here is the solution to problem 3 : primes = 2 : filter ((==1) . length . primeFactors) [3,5..] primeFactors n = factor n primes where factor n (p:ps) | p*p > n = [n] | n `mod` p == 0 = p : factor (n `div` p) (p:ps) | otherwise = factor n ps problem_3 = last (primeFactors 317584931803) My naive reading of this is that primes is defined in terms of primeFactors , which is defined in terms of primes

2-3-5-7 wheel factorization seems to skip prime number 331

这一生的挚爱 提交于 2019-12-04 12:37:00
When following the procedure on wikipedia for wheel factorization , I seem to have stumbled into a problem where the prime number 331 is treated as a composite number if I try to build a 2-3-5-7 wheel. With 2-3-5-7 wheel, 2*3*5*7=210. So I setup a circle with 210 slots and go through steps 1-7 without any issues. Then I get to step 8 and strike off the spokes of all multiples of prime numbers, I eventually strike off the spoke rooted at 121, which is a multiple of 11, which is a prime. For the spoke rooted at 121, 121 + 210 = 331. Unfortunately, 331 is a prime number. Is the procedure on

Dense Cholesky update in Python

大城市里の小女人 提交于 2019-12-04 11:28:17
问题 Could anyone point me to a library/code allowing me to perform low-rank updates on a Cholesky decomposition in python (numpy)? Matlab offers this functionality as a function called 'cholupdate'. LINPACK also has this functionality, but it has (to my knowledge) not yet been ported to LAPACK and hence isn't available in e.g. scipy. I found out that scikits.sparse offers a similar function based on CHOLMOD, but my matrices are dense. Is there any code available for python with 'cholupdate''s

programmatically factorize a large number

旧时模样 提交于 2019-12-04 05:22:04
Alright, so I have a huge number f . This number is just over 100 digits long, actually. I know that the factors are of approximately the same size. If I have limited resources and time, what language and algorithm should I use? I am including the length of time to code the algorithm in the restricted time. Thoughts? EDIT: By limited, I mean in the least amount of time possible. Mysticial The state-of-the-art prime factorization algorithm is the quadratic sieve and its variants. For numbers larger than 100 digits, the number sieve becomes more efficient. There's an open-source implementation

Dense Cholesky update in Python

老子叫甜甜 提交于 2019-12-03 08:24:28
Could anyone point me to a library/code allowing me to perform low-rank updates on a Cholesky decomposition in python (numpy)? Matlab offers this functionality as a function called 'cholupdate'. LINPACK also has this functionality, but it has (to my knowledge) not yet been ported to LAPACK and hence isn't available in e.g. scipy. I found out that scikits.sparse offers a similar function based on CHOLMOD, but my matrices are dense. Is there any code available for python with 'cholupdate''s functionality that's compatible with numpy? Thanks! Here is a Python package that does rank 1 updates and

Finding prime factors

陌路散爱 提交于 2019-11-30 05:26:58
#include <iostream> using namespace std; void whosprime(long long x) { bool imPrime = true; for(int i = 1; i <= x; i++) { for(int z = 2; z <= x; z++) { if((i != z) && (i%z == 0)) { imPrime = false; break; } } if(imPrime && x%i == 0) cout << i << endl; imPrime = true; } } int main() { long long r = 600851475143LL; whosprime(r); } I'm trying to find the prime factors of the number 600851475143 specified by Problem 3 on Project Euler (it asks for the highest prime factor, but I want to find all of them). However, when I try to run this program I don't get any results. Does it have to do with how

efficient ways of finding the largest prime factor of a number

混江龙づ霸主 提交于 2019-11-29 09:40:03
问题 I'm doing this problem on a site that I found (project Euler), and there is a question that involves finding the largest prime factor of a number. My solution fails at really large numbers so I was wondering how this code could be streamlined? """ Find the largest prime of a number """ def get_factors(number): factors = [] for integer in range(1, number + 1): if number%integer == 0: factors.append(integer) return factors def test_prime(number): prime = True for i in range(1, number + 1): if i

Factor a large number efficiently with gmp

陌路散爱 提交于 2019-11-29 04:36:58
I need to get all the prime factors of large numbers that can easily get to 1k bits. The numbers are practically random so it shouldn't be hard. How do I do it efficiently? I use C++ with GMP library. EDIT: I guess you all misunderstood me. What I mean by prime a number is to get all prime factors of the number. Sorry for my english, in my language prime and factor are the same :) clarification (from OP's other post): What I need is a way to efficiently factor(find prime factors of a number) large numbers(may get to 2048 bits) using C++ and GMP(Gnu Multiple Precession lib) or less preferably

Finding prime factors

泄露秘密 提交于 2019-11-29 03:55:51
问题 #include <iostream> using namespace std; void whosprime(long long x) { bool imPrime = true; for(int i = 1; i <= x; i++) { for(int z = 2; z <= x; z++) { if((i != z) && (i%z == 0)) { imPrime = false; break; } } if(imPrime && x%i == 0) cout << i << endl; imPrime = true; } } int main() { long long r = 600851475143LL; whosprime(r); } I'm trying to find the prime factors of the number 600851475143 specified by Problem 3 on Project Euler (it asks for the highest prime factor, but I want to find all

I have a Python list of the prime factors of a number. How do I (pythonically) find all the factors?

空扰寡人 提交于 2019-11-29 03:38:35
I'm working on a Project Euler problem which requires factorization of an integer. I can come up with a list of all of the primes that are the factor of a given number. The Fundamental Theorem of Arithmetic implies that I can use this list to derive every factor of the number. My current plan is to take each number in the list of base primes and raise its power until it is no longer an integer factor to find the maximum exponents for each prime. Then, I will multiply every possible combination of prime-exponent pairs. So for example, for 180: Given: prime factors of 180: [2, 3, 5] Find maximum