![]() |
| | #46 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,354
| Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is offline | |
| | #48 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,354
| Quote:
In a way, this is similiar to the requirements of cryptographic algorithms that need large primes (say, produce any 2 primes that meet the size requirements, as fast as possible), hence the choice of the same commonly used algorithm is natural, in retrospect.
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is offline | |
| | #49 |
| Rampaging 35 Stone Welsh Join Date: Apr 2007
Posts: 2,924
| yes, both CUDA and OpenMP are available. Please specify which of cuda.lib or cudart.lib your submission requires. OpenMP is limited to version 2.0 as thats what 2008 supports. ah, i see now, so basically he is using a non-deterministic approach. If a number fails the test it is definately NOT prime (spectacular failure), but if it passes you cant be 100% sure that it IS prime (unconvincing success). This is an acceptable optimization since it could be applied as a definitive test to weed out many strong pseudo primes. It could then be made comprehensive by applying the modified Sieve of Eratosthenes in the base code. So we run the computationally inexpensive test first and only if it fails to prove a number composite do we apply the expensive test. Although I think i will perhaps switch to AKS for the verification routine.
__________________ He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet Last edited by abachler; 12-02-2008 at 10:06 AM. |
| abachler is offline | |
| | #50 |
| Registered User Join Date: May 2006
Posts: 45
| Here's mine. I hope I didn't break any rules; according to the first post I should have only one function, and I have 2 (+main). If it needs any modifications to be accepted let me know. Runs in 0.3 secs on my comp. According to my tests it's correct. If it doesn't work for you in any way, I can try again right? |
| Sfel is offline | |
| | #51 | ||
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| Quote:
Quote:
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot | ||
| brewbuck is offline | |
| | #52 | |
| Rampaging 35 Stone Welsh Join Date: Apr 2007
Posts: 2,924
| Quote:
I think you can actually reduce k further by choosing specific values for Code: a = {2 , 7, 61 }
__________________ He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet | |
| abachler is offline | |
| | #53 |
| Rampaging 35 Stone Welsh Join Date: Apr 2007
Posts: 2,924
| I think Sfel did even better ...
__________________ He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet |
| abachler is offline | |
| | #54 |
| Registered User Join Date: May 2006
Posts: 45
| For those who are interested in the method, I used the sieve of eratosthenes in the following way: 1. Figure out a maximum range (hi) such that the interval [lo = 2^31 + 1, hi] contains at least 100 000 primes. 2. Generate prime numbers (using the sieve) up to sqrt(hi) 3. For each of these primes, find its lowest multiple which is >= lo. Starting from that, mark all its multiples which are <= hi as not prime. 4. All the numbers in the interval [lo, hi] that are not marked as not prime are definitely prime. So basically, the trick is figuring out how to generalize the sieve of eratosthenes to work for any interval [a,b]. The only disadvantage would be the memory used (I think I use about 2 megs for one of the x arrays), so if you were to ask for, say, a million primes, I'd probably have to resort to using bitsets or bitwise operations to lower used memory. |
| Sfel is offline | |
| | #55 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,354
| Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is offline | |
| | #56 |
| Hail to the king, baby. Join Date: Oct 2008 Location: Faroe Islands
Posts: 713
| Is it hard to make an algorithm for prime numbers o.O? I know this dude in Gmod who made one using Wire... Didn't look comlicated at all :P Oh and I guess 1991 is a prime number! Or was it 1993... |
| Akkernight is offline | |
| | #57 | ||
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,354
| Quote:
Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | ||
| laserlight is offline | |
| | #58 |
| Rampaging 35 Stone Welsh Join Date: Apr 2007
Posts: 2,924
| so was 2003 and the next one will be 2011, but then so is 18446744073709551557 there is a rather broad line between numerical analysis and numerology.
__________________ He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet |
| abachler is offline | |
| | #59 |
| Ex scientia vera Join Date: Sep 2007
Posts: 426
| It was my intention to participate in this challenge, so I whipped up a modified version of the Sieve of Eratosthenes, where one byte represents 8 numbers. However, I have had some trouble making the code work in a specified range, but I haven't taken the time to look at it properly. It can primes ranging from 1 to 80 million or so in a matter of seconds so far, I'll just have to see if I can get it to work properly.
__________________ "What's up, Doc?" "'Up' is a relative concept. It has no intrinsic value." |
| IceDane is offline | |
| | #60 |
| Rampaging 35 Stone Welsh Join Date: Apr 2007
Posts: 2,924
| The smaller numbers (under 2^32) are generally very easy to prove prime or composite. 64 bit numbers are much slower, both because the math takes twice the bandwidth per variable, and because the proofs themselves are more expensive.
__________________ He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet |
| abachler is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| xor linked list | adramalech | C Programming | 23 | 10-14-2008 10:13 AM |
| prime number program with function | mackieinva | C Programming | 17 | 09-20-2007 08:36 AM |
| Prime Number stops after 29, but why? | Daveo | C Programming | 22 | 09-17-2004 10:55 AM |
| Somewhat new to c++, adding Prime number and Sqrt featre to program... | thynksheraze | C++ Programming | 3 | 01-14-2003 10:34 PM |
| Random number generator | Caze | C++ Programming | 6 | 12-03-2002 08:10 AM |