Skip to content

Instantly share code, notes, and snippets.

@nerdralph
Created Dec 7, 2020
Embed
What would you like to do?
odd integer inverse calculator
// Ralph Doncaster 2020 public domain software
// calculate the 64-bit inverse of odd integers
#include <stdio.h>
#include <stdint.h>
#define END_RANGE 9999
int main()
{
uint64_t neg1 = (uint64_t) -1LL;
uint64_t n = 3LLU;
uint64_t inverse = neg1 / n;
do {
uint64_t inverse = neg1 / n;
uint64_t try = 1LLU;
do {
if ( ((inverse * try + 1) *n ) == 1 ) printf("1/%llu = %llu\n", n, inverse * try + 1);
} while ( try++ < n);
n += 2;
} while (n <= END_RANGE);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment