22

I think I've made a mistake...

(Sorry for the quality tho)

Comments
  • 26
    Yes, you made two:
    Using eclipse
    Taking a picture instead of a screenshot
  • 0
    It could be 'count' that messes stuff up. Have you tried using 'o < i / 2' and adding primes at the end of your array instead?
  • 2
    @Niddam honestly I was bored and wanted to save all those prime numbers in a .txt just in case (no one knows when you will need a prime number~) but my code took 1hr to finish this and I just moved to other things. Also, I changed the code a little since I posted this: saved 1, 2 and 3 since the beginning and start comparing only even numbers and other rule that I don't really understand but that I found in an old math book. Now it runs way faster than it did originally. And, in case you are wondering: 9999991 is the biggest prime number within 1 and 10M and there are 664580 prime numbers.
  • 1
    @vrpg1998 i dont know what you need them for? But, making it json/xml and upload them to github will be perfect(i would do it for you) so others don't reinvent the wheel?
  • 0
    @curlyDev life is like prime numbers, no one knows what will happen.
    ¯\_(ツ)_/¯ (maybe for something that needs random numbers that file will help...)
  • 0
    Project Euler problem? :-)
  • 1
    @kaqqao I do understand it, I was too lazy to use it.
  • 0
    @OnlyBytes No haha I just was bored 😛
  • 4
    Well this code is wrong in so many levels ;)
    You can run from 2to(I/2) in the inner loop and you can use mod instead of an array
    There are more hacks, such as checking if the number is odd and acting accordingly
  • 4
    For anyone actually interested:

    1st tge running time on this is horrible. It's n^2 and can be reduced to n root n at best (and I'm not even talking about implementation). If you want to do thus later on, google prime number seive. For context my seive takes less than a second to generate all primes less than 10M, instead of the ten hours it would take you.

    2nd, never print out a number you're computing unless it's for debugging. IO takes longer than CPU tasks and can end up slowing your progress by a lot.

    3rd, there's a site online be with "prime facts". I use it often whrn I want to find a 300 digit prime for example. Just Google "the prime pages"
  • 2
    1 is not prime
  • 0
    @soXx I thought it was until yesterday...
  • 0
    Thanks for your comments! This is what help people to grew professionally and with all I've read here I learned things I didn't know. I really appreciate that you took your time to help me. :)
  • 0
    I wrote a thing like this once. Never felt like optimising it, but got it from not finishing after a day and a half, to finishing the first billion or so prime numbers in minutes. I will try to dig it up if you want.
  • 1
    WHAT KIND OF HUMAN ARE YOU!!!! YOU ARE USE ECLIPSE IS ONE THING BUT THE FREAKING WHITE THEME DAMN
Add Comment