prime-factoring

Prime factors in Haskell

白昼怎懂夜的黑 提交于 2019-12-20 10:34:16
问题 I'm new to Haskell. How to generate a list of lists which contains prime factors of next integers? Currently, I only know how to generate prime numbers: primes = map head $ iterate (\(x:xs) -> [y | y<-xs, y `mod` x /= 0 ]) [2..] 回答1: A simple approach to determine the prime factors of n is to search for the first divisor d in [2..n-1] if D exists: return d : primeFactors(div n d) otherwise return n (since n is prime) Code: prime_factors :: Int -> [Int] prime_factors 1 = [] prime_factors n |

Unique factorization with counter

浪尽此生 提交于 2019-12-20 07:53:56
问题 I am trying to build a program in JAVA which uses Unique factorization theorem. I mean, get a number>1 from user and print all the unique factorization with a counter. for ex, for 100 the output should be 2 2 5 2 since 100=2*2*5*5 and for 23 the output should be 23 if the input is 6, the output will be 2 3 and last example, for 8112, output should be 2 4 3 13 2 so far, I implement a code which gives the first column and correct for prime numbers. however I did not succeed to count when

Finding the optimum column and row size for a table with n elements and a given range for its proportion

做~自己de王妃 提交于 2019-12-20 03:42:29
问题 I am looking for an optimum way to create a table from n elements so that ideally there are no empty cells, but at the same time the proportion of the table dimensions columns / rows becomes as close to 1 as possible. Of course if n is a square number it is easy since then cols = rows = sqrt( n ); If n is a prime number it is also clear that there will be empty cells, so my current way to handle this is: rows = floor( sqrt(n) ); cols = ceil( n / rows ); For all other cases my plan is to get

Factorizing a number in Python

↘锁芯ラ 提交于 2019-12-19 09:16:10
问题 Here's my code: def factorize(n): sieve = [True] * (n + 1) for x in range(2, int(len(sieve) ** 0.5) + 1): if sieve[x]: for i in range(x + x, len(sieve), x): sieve[i] = False lowerPrimes = i for i in range(2, len(sieve)) if sieve[i]] and (n % i == 0)] return lowerPrimes factorize(n) returns all prime factors of the given value n . As you can see, it first makes an Eratosthenes sieve for n and then uses a list comprehension to return all values in the sieve that are factors of n . It works

Factorizing a number in Python

夙愿已清 提交于 2019-12-19 09:16:05
问题 Here's my code: def factorize(n): sieve = [True] * (n + 1) for x in range(2, int(len(sieve) ** 0.5) + 1): if sieve[x]: for i in range(x + x, len(sieve), x): sieve[i] = False lowerPrimes = i for i in range(2, len(sieve)) if sieve[i]] and (n % i == 0)] return lowerPrimes factorize(n) returns all prime factors of the given value n . As you can see, it first makes an Eratosthenes sieve for n and then uses a list comprehension to return all values in the sieve that are factors of n . It works

Prime factorization of a factorial

拟墨画扇 提交于 2019-12-19 03:12:40
问题 I need to write a program to input a number and output its factorial's prime factorization in the form: 4!=(2^3)*(3^1) 5!=(2^3)*(3^1)*(5^1) The problem is I still can't figure out how to get that result. Apparently each first number in brackets is for the ascending prime numbers up until the actual factorial. The second number in brackets is the amount of times the number occurs in the factorial. What I can't figure out is for example in 5!=(2^3)*(3^1)*(5^1) , how does 2 only occur 3 times, 3

Find the smallest regular number that is not less than N

喜欢而已 提交于 2019-12-18 23:13:33
问题 Regular numbers are numbers that evenly divide powers of 60. As an example, 60 2 = 3600 = 48 × 75, so both 48 and 75 are divisors of a power of 60. Thus, they are also regular numbers. This is an extension of rounding up to the next power of two. I have an integer value N which may contain large prime factors and I want to round it up to a number composed of only small prime factors (2, 3 and 5) Examples: f(18) == 18 == 2 1 * 3 2 f(19) == 20 == 2 2 * 5 1 f(257) == 270 == 2 1 * 3 3 * 5 1 What

Find the smallest regular number that is not less than N

穿精又带淫゛_ 提交于 2019-12-18 23:13:20
问题 Regular numbers are numbers that evenly divide powers of 60. As an example, 60 2 = 3600 = 48 × 75, so both 48 and 75 are divisors of a power of 60. Thus, they are also regular numbers. This is an extension of rounding up to the next power of two. I have an integer value N which may contain large prime factors and I want to round it up to a number composed of only small prime factors (2, 3 and 5) Examples: f(18) == 18 == 2 1 * 3 2 f(19) == 20 == 2 2 * 5 1 f(257) == 270 == 2 1 * 3 3 * 5 1 What

Brute-force, single-threaded prime factorization

扶醉桌前 提交于 2019-12-17 17:34:41
问题 Up for consideration is the following function which can be used to (relatively quickly) factor a 64-bit unsigned integer into its prime factors. Note that the factoring is not probabalistic (i.e., it is exact). The algorithm is already fast enough to find that a number is prime or has few very large factors in a matter of several seconds, on modern hardware. The question: Can any improvements be made to the algorithm presented, while keeping it single-threaded, so that it can factor

Finding largest prime number out of 600851475143?

六月ゝ 毕业季﹏ 提交于 2019-12-17 03:19:27
问题 I'm trying to solve problem 3 from http://projecteuler.net. However, when I run thing program nothing prints out. What am I doing wrong? Problem: What is the largest prime factor of the number 600851475143 ? public class project_3 { public boolean prime(long x) // if x is prime return true { boolean bool = false; for(long count=1L; count<x; count++) { if( x%count==0 ) { bool = false; break; } else { bool = true; } } return bool; } public static void main(String[] args) { long ultprime = 0L; /