primes

How do I generate a 160 bit prime number in java?

吃可爱长大的小学妹 提交于 2019-12-21 05:07:47
问题 I want to generate a 160-bit prime number in java. I know that I'll have to loop through all the 160-bit numbers and for any number n , I'll have to check if they are divisible by any primes less than sqroot(n) or by any primality test like Miller-Rabin test . My questions are: Is there any specific library which does this? Is there any other (better) way to do this? 回答1: BigInteger.probablePrime(160, new Random()) generates a BigInteger that is almost certainly prime -- the probability that

Does a library for prime-related functions exist for Python?

喜夏-厌秋 提交于 2019-12-21 03:36:20
问题 I've just implemented the Miller-Rabin-Test and a simple function for factorizing numbers. Both could be done better and at least the Miller-Rabin-Test is well-known. So could you please tell me if a Python-Library, that implements such common prime functions exists or why no such library exists? 回答1: gmpy2 supports a variety of pseudoprime tests. The Miller-Rabin test is available as gmpy2.is_strong_prp() . gmpy2 does not have any factorization code yet. Disclaimer: I'm the maintainer of

Are You A Prime Number

元气小坏坏 提交于 2019-12-21 02:34:05
问题 I've been interested in the problem of finding a better prime number recognizer for years. I realize this is a huge area of academic research and study - my interest in this is really just for fun. Here was my first attempt at a possible solution, in C (below). My question is, can you suggest an improvement (without citing some other reference on the net, I'm looking for actual C code)? What I'm trying to get from this is a better understanding of determining performance complexity of a

Converting prime numbers [duplicate]

我只是一个虾纸丫 提交于 2019-12-20 21:48:17
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: Help with algorithm problem from SPOJ Came across this interview question. Given two n-digit prime numbers, convert the first prime number to the second changing one digit at a time. The intermediate numbers also need to be prime. This needs to be done in the minimum number of steps (checking for primality and changing a digit are considered steps) E.g. convert 1033 to 8179 (1033->1733->3733->.......->8179) 回答1:

how to generate numbers given their prime factors, but with unknown exponents? [duplicate]

六眼飞鱼酱① 提交于 2019-12-20 17:57:06
问题 This question already has answers here : Closed 8 years ago . Possible Duplicates: nth ugly number Find the Kth least number for expression (2^x)*(3^y)*(5^z) I'm wondering how to solve this problem in a fast and elegant way: We define "ugly" every number n which can be written in the form: 2^x * 3^y * 5^z;, where x,y and z are natural numbers. Find the 1500th ugly number. E.g. the first "ugly" numbers are: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, ... I've tried to solve this problem using brute

how to generate numbers given their prime factors, but with unknown exponents? [duplicate]

╄→гoц情女王★ 提交于 2019-12-20 17:57:04
问题 This question already has answers here : Closed 8 years ago . Possible Duplicates: nth ugly number Find the Kth least number for expression (2^x)*(3^y)*(5^z) I'm wondering how to solve this problem in a fast and elegant way: We define "ugly" every number n which can be written in the form: 2^x * 3^y * 5^z;, where x,y and z are natural numbers. Find the 1500th ugly number. E.g. the first "ugly" numbers are: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, ... I've tried to solve this problem using brute

Counting coprimes in a sequence

亡梦爱人 提交于 2019-12-20 12:43:15
问题 Having a sequence of n <= 10^6 integers, all not exceeding m <= 3*10^6, I'd like to count how many coprime pairs are in it. Two numbers are coprime if their greatest common divisor is 1. It can be done trivially in O(n^2 log n), but this is obviously way to slow, as the limit suggests something closer to O(n log n). One thing than can be done quickly is factoring out all the numbers, and also throwing out multiple occurences of the same prime in each, but that doesn't lead to any significant

C#: Implementation of the Sieve of Atkin

泪湿孤枕 提交于 2019-12-20 10:48:11
问题 I was wondering if someone here have a good implementation of the Sieve of Atkin that they would like to share. I am trying to implement it, but can't quite wrap my head around it. Here is what I have so far. public class Atkin : IEnumerable<ulong> { private readonly List<ulong> primes; private readonly ulong limit; public Atkin(ulong limit) { this.limit = limit; primes = new List<ulong>(); } private void FindPrimes() { var isPrime = new bool[limit + 1]; var sqrt = Math.Sqrt(limit); for

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 |

Proving the primality of strong probable primes

為{幸葍}努か 提交于 2019-12-20 10:25:37
问题 Using the probabilistic version of the Miller-Rabin test, I have generated a list of medium-large (200-300 digit) probable primes. But probable ain't good enough! I need to know these numbers are prime. Is there a library -- preferably wrapped or wrappable in Python -- that implements one of the more efficient primality proving algorithms? Alternatively, does anyone know where I can find a clear , detailed , and complete description of ECPP (or a similarly fast algorithm) that does not assume