Skip to content

Instantly share code, notes, and snippets.

@nerdralph
Created December 7, 2020 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nerdralph/aba30d4d1145bcc9129f1b97604dc480 to your computer and use it in GitHub Desktop.
Save nerdralph/aba30d4d1145bcc9129f1b97604dc480 to your computer and use it in GitHub Desktop.
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