loop for finding possible odd divisors

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • scienceman88
    New Member
    • Aug 2009
    • 85

    #16
    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

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #17
      Originally posted by scienceman88
      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
      1) Yes I know, I've always been a smartypants; my mother dropped me on my head when I was a baby ;-)

      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.

      Jos

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #18
        Originally posted by scienceman88
        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
        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,

        Jos

        Comment

        • scienceman88
          New Member
          • Aug 2009
          • 85

          #19
          Originally posted by JosAH
          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,

          Jos
          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 less

          Comment

          • scienceman88
            New Member
            • Aug 2009
            • 85

            #20
            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 code

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #21
              Originally posted by scienceman88
              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 less
              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,

              Jos

              Comment

              • scienceman88
                New Member
                • Aug 2009
                • 85

                #22
                I have no Idea how to josah

                Comment

                • JosAH
                  Recognized Expert MVP
                  • Mar 2007
                  • 11453

                  #23
                  Originally posted by scienceman88
                  I have no Idea how to josah
                  That is not very a scientific attitude (despite the suggestion of your name). Can you come up with a function that returns a C string "file0", "file1", "file2" ... everytime you call it? If so you're halfway there ...

                  kind regards,

                  Jos

                  Comment

                  • scienceman88
                    New Member
                    • Aug 2009
                    • 85

                    #24
                    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

                    • JosAH
                      Recognized Expert MVP
                      • Mar 2007
                      • 11453

                      #25
                      Originally posted by scienceman88
                      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.
                      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.

                      Jos

                      Comment

                      • JosAH
                        Recognized Expert MVP
                        • Mar 2007
                        • 11453

                        #26
                        Originally posted by hsheboul
                        To test for a number whether it's a prime or not is "undecidabl e," and in terms of time efficiency, I think it's NP-Hard; NP stands for None-polynomial.
                        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,

                        Jos

                        Comment

                        • scienceman88
                          New Member
                          • Aug 2009
                          • 85

                          #27
                          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

                          • JosAH
                            Recognized Expert MVP
                            • Mar 2007
                            • 11453

                            #28
                            Originally posted by scienceman88
                            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)
                            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 ...

                            kind regards,

                            Jos

                            Comment

                            • scienceman88
                              New Member
                              • Aug 2009
                              • 85

                              #29
                              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 3

                              Comment

                              • scienceman88
                                New Member
                                • Aug 2009
                                • 85

                                #30
                                Originally posted by JosAH
                                That is not very a scientific attitude (despite the suggestion of your name). Can you come up with a function that returns a C string "file2", "file1", "file2" ... everytime you call it? If so you're halfway there ...

                                kind regards,

                                Jos
                                I only picked this name because I like science and crap_programmer and crappy programmer are already taken.

                                Comment

                                Working...