Guest User

Untitled

a guest
Dec 19th, 2015
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <gmp.h>
  3. #include <string.h>
  4.  
  5. static int _nthp[100000];
  6.  
  7. int nthp(int n) {
  8. mpz_t p;
  9. if (_nthp[n] != 0)
  10. return _nthp[n];
  11.  
  12. mpz_init_set_ui(p, 1);
  13. for (int i = 0; i < n; ++i)
  14. mpz_nextprime(p, p);
  15. int q = mpz_get_ui(p);
  16. mpz_clear(p);
  17. return ((_nthp[n] = q));
  18. }
  19.  
  20. void fp(mpz_t z, int n) {
  21. mpz_set_ui(z, 1);
  22. for (int i = 1; i <= n; ++i) {
  23. int x = i + nthp(i);
  24. //printf("x=%d+%d=%d\n", i, nthp(i),x);
  25. mpz_mul_ui(z, z, x);
  26. }
  27. }
  28.  
  29. int divt(int n) {
  30. mpz_t z, f;
  31. mpz_init(z);
  32. mpz_init(f);
  33.  
  34. fp(z, n);
  35. mpz_fac_ui(f, n);
  36.  
  37. //printf("%d\t", n);
  38. //mpz_out_str(stdout, 10, z);
  39. //printf("\t");
  40. //mpz_out_str(stdout, 10, f);
  41. //printf("\n");
  42.  
  43. int d = mpz_divisible_p(z, f);
  44. mpz_clear(z);
  45. mpz_clear(f);
  46.  
  47. return d;
  48. }
  49.  
  50. int main() {
  51. setbuf(stdout, NULL);
  52. memset(_nthp, 0, sizeof(_nthp));
  53. for (int i = 1; i < 100000; ++i) {
  54. printf("%d\t%d\n", i, divt(i));
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment