factorization

More ruby-like solution to this problem?

只愿长相守 提交于 2019-12-12 10:25:47
问题 I am learning ruby and practicing it by solving problems from Project Euler. This is my solution for problem 12. # Project Euler problem: 12 # What is the value of the first triangle number to have over five hundred divisors? require 'prime' triangle_number = ->(num){ (num *(num + 1)) / 2 } factor_count = ->(num) do prime_fac = Prime.prime_division(num) exponents = prime_fac.collect { |item| item.last + 1 } fac_count = exponents.inject(:*) end n = 2 loop do tn = triangle_number.(n) if factor

Factoring a quantum state

谁都会走 提交于 2019-12-09 11:22:54
问题 I'm looking for algorithms that take an arbitrary quantum state made up of a sum of weighted classical states made up of bits, like this: |0000>/2 - |0011>/2 + |0100>/2 - |0111>/2 and factor it into a more compact form using tensor products, like this: |0> x (|0> + |1>) x (|00> - |11>) / 2 I want to use the algorithm as a way of visualizing/simplifying the state of a (simulated) quantum circuit. For individual qubits I know I can just pair all the states with the state where the bit is

Calculating Eulers Totient Function for very large numbers JAVA

早过忘川 提交于 2019-12-08 18:28:31
I've managed to get a version of Eulers Totient Function working, albeit one that works for smaller numbers (smaller here being smaller compared to the 1024 bit numbers I need it to calculate) My version is here - public static BigInteger eulerTotientBigInt(BigInteger calculate) { BigInteger count = new BigInteger("0"); for(BigInteger i = new BigInteger("1"); i.compareTo(calculate) < 0; i = i.add(BigInteger.ONE)) { BigInteger check = GCD(calculate,i); if(check.compareTo(BigInteger.ONE)==0) {//coprime count = count.add(BigInteger.ONE); } } return count; } While this works for smaller numbers,

Implementing a factorisation method in Haskell

微笑、不失礼 提交于 2019-12-08 15:26:29
I am doing question 266 at Project Euler and after a bit of searching, found this method of quickly finding the factors of a number. What you do is find all the permutations of the prime factors of a number: these are its factors. I already have a module to find the prime power factors of a number, eg: Main> primePowerFactors 196 [(2,2),(7,2)] This is basically showing that: 2^2 * 7^2 == 196 . From here I want to find all the permutations of those powers, to give the factors of 196 thusly: (2^0)(7^0) = 1 (2^1)(7^0) = 2 (2^2)(7^0) = 4 (2^0)(7^1) = 7 (2^1)(7^1) = 14 (2^2)(7^1) = 28 (2^0)(7^2) =

Calculating Eulers Totient Function for very large numbers JAVA

↘锁芯ラ 提交于 2019-12-08 08:21:15
问题 I've managed to get a version of Eulers Totient Function working, albeit one that works for smaller numbers (smaller here being smaller compared to the 1024 bit numbers I need it to calculate) My version is here - public static BigInteger eulerTotientBigInt(BigInteger calculate) { BigInteger count = new BigInteger("0"); for(BigInteger i = new BigInteger("1"); i.compareTo(calculate) < 0; i = i.add(BigInteger.ONE)) { BigInteger check = GCD(calculate,i); if(check.compareTo(BigInteger.ONE)==0) {/

Implementing a factorisation method in Haskell

霸气de小男生 提交于 2019-12-08 04:19:34
问题 I am doing question 266 at Project Euler and after a bit of searching, found this method of quickly finding the factors of a number. What you do is find all the permutations of the prime factors of a number: these are its factors. I already have a module to find the prime power factors of a number, eg: Main> primePowerFactors 196 [(2,2),(7,2)] This is basically showing that: 2^2 * 7^2 == 196 . From here I want to find all the permutations of those powers, to give the factors of 196 thusly: (2

I have a new algorithm to find factors or primes in linear time - need verification for this

不问归期 提交于 2019-12-06 22:38:23
问题 I have developed an algorithm to find factors of a given number. Thus it also helps in finding if the given number is a prime number. I feel this is the fastest algorithm for finding factors or prime numbers. This algorithm finds if a give number is prime in time frame of 5*N (where N is the input number). So I hope I can call this a linear time algorithm. How can I verify if this is the fastest algorithm available? Can anybody help in this matter? (faster than GNFS and others known)

Why is this Haskell code snippet not infinitely recursive?

风流意气都作罢 提交于 2019-12-06 17:12:50
问题 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

programmatically factorize a large number

百般思念 提交于 2019-12-06 00:56:09
问题 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. 回答1: The state-of-the-art prime factorization algorithm is the quadratic sieve and its variants. For numbers larger

I have a new algorithm to find factors or primes in linear time - need verification for this

旧城冷巷雨未停 提交于 2019-12-05 03:00:55
I have developed an algorithm to find factors of a given number. Thus it also helps in finding if the given number is a prime number. I feel this is the fastest algorithm for finding factors or prime numbers. This algorithm finds if a give number is prime in time frame of 5*N (where N is the input number). So I hope I can call this a linear time algorithm. How can I verify if this is the fastest algorithm available? Can anybody help in this matter? (faster than GNFS and others known) Algorithm is given below Input: A Number (whose factors is to be found) Output: The two factor of the Number.