Skip to content

Instantly share code, notes, and snippets.

@Gro-Tsen
Created January 5, 2023 09:07
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 Gro-Tsen/f4109b0d86e11437d7f2912ea544ad91 to your computer and use it in GitHub Desktop.
Save Gro-Tsen/f4109b0d86e11437d7f2912ea544ad91 to your computer and use it in GitHub Desktop.
/* 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