Created
December 7, 2020 16:08
-
-
Save nerdralph/aba30d4d1145bcc9129f1b97604dc480 to your computer and use it in GitHub Desktop.
odd integer inverse calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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