5)I want to use ftell and f seek to keep the files small enough to read in dos 4GB(a little less for possible overflow) I think so
loop for finding possible odd divisors
Collapse
This topic is closed.
X
X
-
-
1) Yes I know, I've always been a smartypants; my mother dropped me on my head when I was a baby ;-)Okay
1)I barely understood your code jos
2)I tried to insert it to file instead and I couldn't get it to work.
3)N= max for unsigned long long integers or about 18,446,744,073, 709,551,615
4) you can use prime numbers before to calculate the next one it follows the sieve of eratosthenes( i know the sieve of atkin is faster but I don't understand it) and those sieves are the only known ways to find all primes except maybe primality testing each number
2) My code simply prints the primes to stdout; it doesn't take rocket science to print the primes to elsewehere.
3) I take your word for it; no, I won't I'll check it ... yep, you're right.
4) both are similar algorithms in disguise: sieves filter out equal factors for all numbers while my primality check filtes out all factors per number. It doesn't need that huge array of bits to keep track of all the numbers.
kind regards.
JosComment
-
Just keep track on the number of bytes written already; when it exceeds a certain threshold, close the file and quit the process. There's no need for ftell() or fseek().
kind regards,
JosComment
-
unless I watch it manually close it and expect it to say next file there is as i know it won't all get into one file of 4 gb or lessComment
-
I can't get it to print to file never worked in more than one function before so unless i have to declare the pointer globally but change it internally I'll never be able to use the codeComment
-
Think 'object based': the 'object' or 'module' takes care of the printing and keeps track of that threshold value; whenever the number of bytes written exceeds that value, close the file, open a next one and reset the number of bytes written. At the end close the last file.
kind regards,
JosComment
-
-
Comment
-
I have one in my original code but I can't even get the file part to work in your code so changing files is pointless also without fseek and ftell I don't know how to track the size of the file as for my name it's because I like science not people like you.Comment
-
Ok, I'll stop answering your questions then but mind you: nobody here is going to do your homework for you; we don't believe in that approach. You have to do your work and when you're stuck we can try to help you.
Bye bye.
JosComment
-
That test most certainly is a decidable problem. It may be a bit tough for large numbers but that's it. For any integral n > 0 I can decide in O(n) whether or not n is a prime number; it isn't even in any NP class of problems.
kind regards,
JosComment
-
I'm not trying to sound mean but the best I've done in understanding you is the original code you posted that doesn't seem to allow a file pointer anywhere where it isn't global(and because it had no comments it took me 30 minutes( and a pasting into my compiler) to figure out as I've never made a program with more than one function) also nobody asked how long I've been using C I've been barely able to do anything and I've been at it less than a full 3 months only thing that helped me learn printing at all is codeguru.com and learning a bit about pointers ( obviously not enough) basically I want something like this:
if (i%x!=0 && x<=sqrt(i)){
x=x+2;
}
and if that shows to be false for all odd numbers under the sqrt(i) and the file size is not bigger than 4 gb then print it to primesx.txt and increase my primes variable by one.Comment
-
Here's a nice reference. Everywhere where I use printf() you can use fprintf() and use a file pointer (which you have opened somewhere before in your code). You have to learn how to crawl before you can walk; you have to learn how to walk before you can run ...I'm not trying to sound mean but the best I've done in understanding you is the original code you posted that doesn't seem to allow a file pointer anywhere where it isn't global also nobody asked how long I've been using C I've been barely able to do anything and I've been at it less than a full 3 months only thing that helped me learn printing at all is codeguru.com and learning a bit about pointers ( obviously not enough)
kind regards,
JosComment
-
when i tried something as simple as this it fails as it goes above 25 the first square number greater than 3^2 that will be incountered if i=i+2 and i starts at 3Comment
-
I only picked this name because I like science and crap_programmer and crappy programmer are already taken.Comment
Comment