• idunnololz@lemmy.world
    link
    fedilink
    English
    arrow-up
    14
    ·
    edit-2
    11 months ago

    How many primes are there before 1 and 2^31. IIRC prime numbers get more and more rare as the number increases. I wouldn’t be surprised if this would pass 99% of tests if tested with all positive 32 bit integers.

    • Kogasa@programming.dev
      link
      fedilink
      English
      arrow-up
      13
      ·
      11 months ago

      Per the prime number theorem, for large enough N the proportion of primes less than or equal to N is approximately 1/log(N). For N = 2^(31) that’s ~0.0465. To get under 1% you’d need N ~ 2^(145).

    • idunnololz@lemmy.world
      link
      fedilink
      English
      arrow-up
      7
      ·
      11 months ago

      Wolfram alpha says it’s about 4.9%. So 4.9% of numbers in the range 1 to 2^31 are prime. It’s more than I expected.