C Board  

Go Back   C Board > Community Boards > Contests Board

Reply
 
LinkBack Thread Tools Display Modes
Old 12-06-2008, 10:00 PM   #61
Ex scientia vera
 
Join Date: Sep 2007
Posts: 426
Quote:
Originally Posted by abachler View Post
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.
Yes, of course, I wasn't trying to say that it would beat the challenge, but that it did at least look somewhat promising. My previous implementation of the sieve of eratosthenes' memory complexity was O(n), where n is the maximum in the range, while this one's is O(n/8) (I am using the O notation correctly, am I not?), and the previous could generate primes under 10 million(Limit due to the heavy memory usage) in 10 or so secs, while the current can do so in .. 3 secs.
__________________
"What's up, Doc?"
"'Up' is a relative concept. It has no intrinsic value."
IceDane is offline   Reply With Quote
Old 12-07-2008, 06:45 AM   #62
-AppearingOnThis..........
 
Join Date: May 2005
Location: Netherlands
Posts: 44
I made this probably a year ago or so, and to be honest I can't really be bothered converting it's interface to the specifications. however, it may be of interest: it can easily calculate >200000 primes above 2^32 in less than 0.4 seconds. it compiles on gcc fine, using the unsigned long long type; not sure about visual c++.

run it like: segprime2 minimum_value maximum_value output_file
eg. segprime2 4294967296 4300000000 outfile.txt will generate 227027 primes

http://sirnot.110mb.com/c/?f=segprime2.c

it uses a 'work array' to maximize its range/number size while minimizing memory usage.

Last edited by SirNot; 12-07-2008 at 06:57 AM.
SirNot is offline   Reply With Quote
Old 12-08-2008, 03:40 PM   #63
Registered User
 
Join Date: Jan 2005
Posts: 7,137
>> while this one's is O(n/8) (I am using the O notation correctly, am I not?)

Not exactly. O(n/8) is equivalent to O(n). In big-O notation all constants are ignored. As n increases, an O(n) running time will increase at the same rate as an O(n/8) running time would, which is why they are considered equivalent.
Daved is offline   Reply With Quote
Old 12-09-2008, 03:14 AM   #64
Ex scientia vera
 
Join Date: Sep 2007
Posts: 426
Quote:
Originally Posted by Daved View Post
>> while this one's is O(n/8) (I am using the O notation correctly, am I not?)

Not exactly. O(n/8) is equivalent to O(n). In big-O notation all constants are ignored. As n increases, an O(n) running time will increase at the same rate as an O(n/8) running time would, which is why they are considered equivalent.
Ah yes, I see. Thank you.
__________________
"What's up, Doc?"
"'Up' is a relative concept. It has no intrinsic value."
IceDane is offline   Reply With Quote
Old 12-09-2008, 05:33 AM   #65
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,929
Quote:
Originally Posted by Daved View Post
>> while this one's is O(n/8) (I am using the O notation correctly, am I not?)

Not exactly. O(n/8) is equivalent to O(n). In big-O notation all constants are ignored. As n increases, an O(n) running time will increase at the same rate as an O(n/8) running time would, which is why they are considered equivalent.
Thats not entirely true, since when comparing two algorithms, O(n/8) would be faster than O(n). In cases where the running times are being compared (which is often) the constants cannot be ignored. Only when it is specifically comparing the complexity to the size n of an arbitrary input can the constants be ignored.
__________________
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 online now   Reply With Quote
Old 12-09-2008, 05:44 AM   #66
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
Right, O(n) ~= O(n/8), it's more a case O(n) != O(log2 n) or O(n^2) - if n is 10000, and you divide by 8, you get 1250. Not a huge number, not a small number. O(log2 n) for n=10000 is about 13, O(n^2) is 100000000.

And more importantly, if we double n, O(n) also doubles. O(n^2) is 4x larger, O(log2 n) is one larger.

So the point about big-O is the ability to predict from a small run (low n), how a larger n will behave - this is a bit more difficult in modern machines with caches, virtual memory and other aspects, but we can still predict with some accuracy what will happen if we for example double the amount of data - will the time double or increase more/less than double?

--
Mats
__________________
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
matsp is offline   Reply With Quote
Old 12-09-2008, 10:40 AM   #67
Registered User
 
Join Date: Jan 2005
Posts: 7,137
>> Only when it is specifically comparing the complexity to the size n of an arbitrary input can the constants be ignored.

But is that not what big-O notation is intended for? If you want to compare running times (which of course is often a relevant endeavor), you shouldn't be using big-O notation.
Daved is offline   Reply With Quote
Old 12-09-2008, 02:43 PM   #68
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,929
Except you arent always comparing actual runnign times, but computational complexity. So one algorithm may solve the problem in O(n log n) time, while another algorithm may solve it in O(n/2 log n) by discarding half the test cases based on some trivially computable feature. e.g. an algorithm that finds all prime numbers between 3 and n > 3 by testing every number, versus the same algorithm that only tests odd numbers between 3 and n > 3.
__________________
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 online now   Reply With Quote
Old 12-09-2008, 04:18 PM   #69
Senior software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 5,381
Quote:
Originally Posted by abachler View Post
Except you arent always comparing actual runnign times, but computational complexity. So one algorithm may solve the problem in O(n log n) time, while another algorithm may solve it in O(n/2 log n) by discarding half the test cases based on some trivially computable feature. e.g. an algorithm that finds all prime numbers between 3 and n > 3 by testing every number, versus the same algorithm that only tests odd numbers between 3 and n > 3.
Except that by definition O(n/2 log n) == O(n log n). Nobody's saying there's no difference in run time, it's just not right to talk about it using big-O.
__________________
"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   Reply With Quote
Old 12-19-2008, 01:33 PM   #70
Amazingly beautiful user.
 
Join Date: Jul 2005
Location: If you knew I'd have to kill you
Posts: 251
If I remember, O(f(x)) = g(x) if there exist constants c, d, and e such that c * f(x) + d >= g(x) for all x > e. Thus, O(n / 8) = O(n), because 8 * (n / 8) + 0 >= n, for all x > 0. (c = 8, d = 0, e = 0)
__________________
Programming Your Mom. http://www.dandongs.com/
CrazyNorman is offline   Reply With Quote
Old 12-19-2008, 01:36 PM   #71
Senior software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 5,381
Quote:
Originally Posted by CrazyNorman View Post
If I remember, O(f(x)) = g(x) if there exist constants c, d, and e such that c * f(x) + d >= g(x) for all x > e. Thus, O(n / 8) = O(n), because 8 * (n / 8) + 0 >= n, for all x > 0. (c = 8, d = 0, e = 0)
Another way to put it is that lim [n -> infinity] f(n)/g(n) = k where k is some positive constant.
__________________
"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   Reply With Quote
Old 10-21-2009, 08:15 PM   #72
Registered User
 
Join Date: Oct 2009
Posts: 1
Greetings, folks.
Congrats on the terrific submissions. I can't find who won - or abachler's source test code. Will someone help me out, please?

Thanks!
deluge01 is offline   Reply With Quote
Old 10-22-2009, 01:46 AM   #73
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 10,366
Sfel, probably.
__________________
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 online now   Reply With Quote
Old 10-23-2009, 07:27 AM   #74
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,929
Nothing like bumping a year old thread.
__________________
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 online now   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 08:59 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22