primes

Why setting HashTable's length to a Prime Number is a good practice?

試著忘記壹切 提交于 2019-12-17 22:24:17
问题 I was going through Eric Lippert's latest Blog post for Guidelines and rules for GetHashCode when i hit this para: We could be even more clever here; just as a List resizes itself when it gets full, the bucket set could resize itself as well, to ensure that the average bucket length stays low. Also, for technical reasons it is often a good idea to make the bucket set length a prime number, rather than 100. There are plenty of improvements we could make to this hash table. But this quick

Prime Number Determination Javascript

不羁的心 提交于 2019-12-17 21:10:49
问题 I am creating a external javascript file. This is for homework. What I am supposed to do is determine if the number that the user enters in is a prime number or not, and displays a message if it is a prime number or not. I have my code written, compiles and everything. But I am cannot seem to figure out with, no matter what number i enter in, the display message always says that that number is a prime number. Can anyone help? Here is my code: var UI; var TV; var HITS; UI = window.prompt(

Checking if an int is prime more efficiently

天大地大妈咪最大 提交于 2019-12-17 20:58:38
问题 I recently was part of a small java programming competition at my school. My partner and I have just finished our first pure oop class and most of the questions were out of our league so we settled on this one (and I am paraphrasing somewhat): "given an input integer n return the next int that is prime and its reverse is also prime for example if n = 18 your program should print 31" because 31 and 13 are both prime. Your .class file would then have a test case of all the possible numbers from

prime numbers c#

被刻印的时光 ゝ 提交于 2019-12-17 20:50:24
问题 I'm new to C#. And I would like to program something like, displaying the prime numbers in a listbox if user will input any integer in the textbox. (that means, if they write 10, it will display the prime numbers from 0-10, or 20 from 0-20, etc). What should I consider first, before I do the programming? I know there are many examples in the internet, but first I would like to know what will I need? Thanks for the tip;-) === Thanks guys. So you're suggesting that it's better to do it first in

Improving pure Python prime sieve by recurrence formula

不打扰是莪最后的温柔 提交于 2019-12-17 18:23:02
问题 I am trying to optimize further the champion solution in prime number thread by taking out the complex formula for sub-list length. len() of the same subsequence is too slow as len is expensive and generating the subsequence is expensive. This looks to slightly speed up the function but I could not yet take away the division, though I do the division only inside the condition statement. Of course I could try to simplify the length calculation by taking out the optimization of starting marking

How does this regular expression work?

百般思念 提交于 2019-12-17 16:06:47
问题 From this article, /^1?$|^(11+?)\1+$/ checks whether a number(its value in unary) is prime or not. Using this, perl -l -e '(1 x $_) !~ /^1?$|^(11+?)\1+$/ && print while ++$_;' returns a list of prime numbers. I do not have enough experience with Perl, but what I understand is that the regular expression will be true for a number that is not prime. So, if we print all numbers that do not produce a true with this expression, we have a list of prime numbers. Thats what the perl query is trying

Prime number calculation fun

烈酒焚心 提交于 2019-12-17 15:57:11
问题 We're having a bit of fun here at work. It all started with one of the guys setting up a Hackintosh and we were wondering whether it was faster than a Windows Box of (nearly) same specs that we have. So we decided to write a little test for it. Just a simple Prime number calculator. It's written in Java and tells us the time it takes to calculate the first n Prime numbers. Optimised version below - now takes ~6.6secs public class Primes { public static void main(String[] args) { int topPrime

Efficient algorithm to get primes between two large numbers

 ̄綄美尐妖づ 提交于 2019-12-17 15:51:41
问题 I'm a beginner in C#, I'm trying to write an application to get primes between two numbers entered by the user. The problem is: At large numbers (valid numbers are in the range from 1 to 1000000000) getting the primes takes long time and according to the problem I'm solving, the whole operation must be carried out in a small time interval. This is the problem link for more explanation: SPOJ-Prime And here's the part of my code that's responsible of getting primes: public void GetPrime() { int

Efficient algorithm to get primes between two large numbers

风格不统一 提交于 2019-12-17 15:51:30
问题 I'm a beginner in C#, I'm trying to write an application to get primes between two numbers entered by the user. The problem is: At large numbers (valid numbers are in the range from 1 to 1000000000) getting the primes takes long time and according to the problem I'm solving, the whole operation must be carried out in a small time interval. This is the problem link for more explanation: SPOJ-Prime And here's the part of my code that's responsible of getting primes: public void GetPrime() { int

Calculating phi(k) for 1<k<N

拜拜、爱过 提交于 2019-12-17 15:32:24
问题 Given a large N, I need to iterate through all phi(k) such that 1 < k < N : time-complexity must be O(N logN) memory-complexity must be sub O(N) (since the values of N will be around 10 12 ) Is it possible? If so, how? 回答1: This can be done with Memory complexity O(Sqrt(N)) and CPU complexity O(N * Log(Log(N))) with an optimized windowed Sieve of Eratosthenes, as implemented in the code example below. As no language was specified and as I do not know Python, I have implemented it in VB.net,