Skip to content

Instantly share code, notes, and snippets.

@m-f-h
m-f-h / k_plus_sigma_k_is_perfect.py
Last active March 10, 2025 05:12 — forked from Radcliffe/k_plus_sigma_k_is_perfect.py
k + sigma(k) is perfect
"""
k_plus_sigma_k_is_perfect.py
edited and modified by MFH
forked from D.Radcliffe
Problem:
The number 10 has a special property. When 10 is added to the sum
of its divisors, the result is 28, which is a perfect number.
10 + sigma(10) = 10 + 1 + 2 + 5 + 10 = 28
@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;