Skip to content

Instantly share code, notes, and snippets.

@m-f-h
m-f-h / isprime.py
Created June 16, 2022 00:22
Provide basic number theory functions isprime, isprimepower, nextprime, primes, prevprime
""" isprime.py
May / June 2022 by M. F. Hasler
SYNOPSIS: very simple implementation of basic Number Theory functions:
isprime(n): return True or False according to whether n is prime or not
nextprime(n, i=1): return the i-th prime > n (i.e., >= n + 1).
prevprime(n, i=1): return the i-th prime < n or 0 if n < prime(n).
primes(n=math.inf, start=2, end=math.inf): return a generator
producing at most n primes in [start, end).
isprimepower(n): return True if n is prime, or
@m-f-h
m-f-h / findNextPrime
Last active February 4, 2022 19:57 — forked from alabombarda/findNextPrime
A simple program in C++ that finds the next prime number above a given number.
// findNextPrime.cpp - return the next larger prime number
// (input taken from command line args or from stdin)
#include <iostream>
int findNextPrime(int n); // given a number n, find the next larger prime number above n
bool isPrime(int n); // given a number n, determine whether it is prime
int main(int argc, char**argv)
{
int input;