Elektrine lite

← Feed

@arichtman@eigenmagic.net

2026-07-20 07:55 UTC

Math fedi, help! I'm looking for a function that calculates the next prime given a starting integer (not guaranteed prime) - i.e. what's the smallest prime larger than this number. It looks like there are some functions for generating primes but nothing with a minimum and all the other articles are basically "loop and test each one" - maybe using a sieve function. Does a nicer mathematic approach exist? #Math #Mathematics #PrimeNumbers #Primes

Replies (3)

  • @BenAveling@infosec.exchange 2026-07-20 08:07

    @arichtman@eigenmagic.net if you’d settle for a prime, larger than x, then maybe. But if it has to be the smallest prime larger than x, then no.

    Open ##3954137

  • @arichtman@eigenmagic.net 2026-07-20 14:24

    For those following along at home so far the score is thus: Prime numbers: 2 Me: (stepped on a landmine, DQed)

    Open ##4220827

  • @lambda_ily@transfem.social 2026-07-20 14:17

    @arichtman@eigenmagic.net This video is very informative on how to optimize the Sieve of Eratosthenes if you only care about one specific prime https://www.youtube.com/watch?v=uJkoI5TnKzA

    Open ##5322844