primes

How do I generate Primes Using 6*k +- 1 rule

故事扮演 提交于 2019-12-03 11:04:47
问题 We know that all primes above 3 can be generated using: 6 * k + 1 6 * k - 1 However we all numbers generated from the above formulas are not prime. For Example: 6 * 6 - 1 = 35 which is clearly divisible by 5. To Eliminate such conditions, I used a Sieve Method and removing the numbers which are factors of the numbers generated from the above formula. Using the facts: A number is said to be prime if it has no prime factors. As we can generate all the prime numbers using the above formulas. If

What does “e is 65537 (0x10001)” mean?

旧街凉风 提交于 2019-12-03 10:40:37
I want to know what the output e is 65537 (0x10001) means. It happens during the RSA Key Generation using openssl genrsa . I know that the dots mean that the number has passed a probe division and the plus is printed out after it passed a miller rabin test. But i can't figure out what the last info message before the RSA key is printed out means. I can't find it in the openssl docs. And I could use it in term paper on prime number generation. Thanks for your help! :) Raymond Tau The "e" is the public exponent, in openssl genrsa , you can use the option -F4 or -3 to choose between 65537 and 3.

How do I find the nearest prime number?

隐身守侯 提交于 2019-12-03 10:40:12
Is there any nice algorithm to find the nearest prime number to a given real number? I only need to search within the first 100 primes or so. At present, I've a bunch of prime numbers stored in an array and I'm checking the difference one number at a time (O(n)?). Rather than a sorted list of primes, given the relatively small range targetted, have an array indexed by all the odd numbers in the range (you know there are no even primes except the special case of 2) and containing the closest prime. Finding the solution becomes O(1) time-wise. I think the 100th prime is circa 541. an array of

Fast Algorithm to find number of primes between two numbers

大城市里の小女人 提交于 2019-12-03 10:38:46
问题 My problem reduces to finding the number of primes between two given numbers.I could have a range as big as 1 to (1000)! and hence I am need of some mathematical optimizations. Clearly the sieve method would be too slow in this case. Is there any mathematical optimization that can be applied - like for instance, taking a smaller subset of this large space and making inferences about the rest of the numbers. P.S: It definitely looks like I might have reached a dead end - but all that I am

Python Beginner's Loop (Finding Primes)

你。 提交于 2019-12-03 08:26:51
I'm truly a beginner at python so I apologise for the lack of knowledge, but the reason I'm asking is that reading the Python manual and tutorial ( http://docs.python.org/2.7/tutorial ) I'm not unable to totally grasp how loops work. I've written some simple programs so I think I get the basics but for whatever reason this program that is meant to list all primes less than or equal to n is not working: n = int(raw_input("What number should I go up to? ")) p = 2 while p <= n: for i in range(2, p): if p%i == 0: p=p+1 print "%s" % p, p=p+1 print "Done" The output when I enter 100 for example is:

Interview question : What is the fastest way to generate prime number recursively? [closed]

浪子不回头ぞ 提交于 2019-12-03 07:50:48
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . Generation of prime number is simple but what is the fastest way to find it and generate( prime numbers) it recursively ? Here is my

No of Pairs of consecutive prime numbers having difference of 6 like (23,29) from 1 to 2 billion

大兔子大兔子 提交于 2019-12-03 07:11:23
How to find number of pairs of consecutive prime numbers having difference of 6 like (23,29) from 1 to 2 billion (using any programming language and without using any external libraries) with considering time complexity? Tried sieve of eratosthenes but getting consecutive primes is challenge Used generators but time complexity is very high The code is: def gen_numbers(n): for ele in range(1,n+1): for i in range(2,ele//2): if ele%i==0: break else: yield ele prev=0 count=0 for i in gen_numbers(2000000000): if i-prev==6: count+=1 prev = i Interesting question! I have recently been working on

How do I generate the first n prime numbers?

倾然丶 夕夏残阳落幕 提交于 2019-12-03 06:46:07
问题 I am learning Ruby and doing some math stuff. One of the things I want to do is generate prime numbers. I want to generate the first ten prime numbers and the first ten only. I have no problem testing a number to see if it is a prime number or not, but was wondering what the best way is to do generate these numbers? I am using the following method to determine if the number is prime: class Integer < Numeric def is_prime? return false if self <= 1 2.upto(Math.sqrt(self).to_i) do |x| return

Converting prime numbers [duplicate]

隐身守侯 提交于 2019-12-03 06:11:39
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) Nice challenge for a rainy Monday evening (it is here, anyway!). This can be done using Dijkstra's algorithm . The first step is to create a graph containing all 4-digit

Fastest modular exponentiation in JavaScript

丶灬走出姿态 提交于 2019-12-03 05:59:26
问题 My problem is to compute (g^x) mod p quickly in JavaScript, where ^ is exponentiation, mod is the modulo operation. All inputs are nonnegative integers, x has about 256 bits, and p is a prime number of 2048 bits, and g may have up to 2048 bits. Most of the software I've found that can do this in JavaScript seems to use the JavaScript BigInt library (http://www.leemon.com/crypto/BigInt.html). Doing a single exponentiation of such size with this library takes about 9 seconds on my slow browser