Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <gmp.h>
- #include <string.h>
- static int _nthp[100000];
- int nthp(int n) {
- mpz_t p;
- if (_nthp[n] != 0)
- return _nthp[n];
- mpz_init_set_ui(p, 1);
- for (int i = 0; i < n; ++i)
- mpz_nextprime(p, p);
- int q = mpz_get_ui(p);
- mpz_clear(p);
- return ((_nthp[n] = q));
- }
- void fp(mpz_t z, int n) {
- mpz_set_ui(z, 1);
- for (int i = 1; i <= n; ++i) {
- int x = i + nthp(i);
- mpz_mul_ui(z, z, x);
- }
- }
- int divt(int n) {
- mpz_t z, f;
- mpz_init(z);
- mpz_init(f);
- fp(z, n);
- mpz_set_ui(f, 1);
- mpz_t p;
- mpz_init_set_ui(p, 1);
- while (1) {
- mpz_nextprime(p, p);
- if (mpz_get_ui(p) > n)
- break;
- mpz_mul(f, f, p);
- }
- mpz_clear(p);
- mpq_t r;
- mpq_init(r);
- mpq_set_num(r, z);
- mpq_set_den(r, f);
- mpq_canonicalize(r);
- int d = mpz_divisible_p(z, f);
- // printf("%d\t", n);
- // mpz_out_str(stdout, 10, mpq_denref(r));
- // printf("\n");
- mpq_clear(r);
- mpz_clear(z);
- mpz_clear(f);
- return d;
- }
- int main() {
- setbuf(stdout, NULL);
- memset(_nthp, 0, sizeof(_nthp));
- for (int i = 1; i < 100000; ++i) {
- printf("%d\t%d\n", i, divt(i));
- }
- }
Add Comment
Please, Sign In to add comment