Created
January 5, 2023 09:07
-
-
Save Gro-Tsen/f4109b0d86e11437d7f2912ea544ad91 to your computer and use it in GitHub Desktop.
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
/* Compute digits of the (pq)-adic idempotent - David A. Madore, 2014-02-03 */ | |
#include <stdio.h> | |
#include <string.h> | |
#include <gmp.h> | |
#ifndef DIGITS | |
#define DIGITS 10000000 | |
#endif | |
#ifndef PRIME_P | |
#define PRIME_P 2 | |
#endif | |
#ifndef PRIME_Q | |
#define PRIME_Q 5 | |
#endif | |
#ifndef BASE | |
#define BASE (PRIME_P * PRIME_Q) | |
#endif | |
int | |
main (void) | |
{ | |
mpz_t modulus; mpz_init (modulus); | |
mpz_ui_pow_ui (modulus, BASE, DIGITS); | |
mpz_t modp; mpz_init (modp); | |
mpz_ui_pow_ui (modp, PRIME_P, DIGITS); | |
mpz_t modq; mpz_init (modq); | |
mpz_ui_pow_ui (modq, PRIME_Q, DIGITS); | |
mpz_t x; mpz_init (x); | |
mpz_invert (x, modp, modq); | |
mpz_mul (x, modp, x); | |
mpz_mod (x, x, modulus); /* Useless? */ | |
char *str = mpz_get_str(NULL, BASE, x); | |
for ( int i = DIGITS - strlen(str) ; i>0 ; i-- ) | |
printf ("0"); | |
puts (str); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment