Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <math.h>
  5. #include <numeric>
  6. #include <fstream>
  7. #include <string.h>
  8. #include <stdlib.h>
  9.  
  10. #include "gmp.h"
  11.  
  12. using namespace std;
  13.  
  14. /*
  15. Case 1, 1, 2, 3, 5, 8, ...
  16. Step 1:
  17. s(x) = x + x^2 + x(s(x) - x) + x^2s(x)
  18. https://www.wolframalpha.com/input/?i=s(x)+%3D+x+%2B+x%5E2+%2B+x(s(x)+-+x)+%2B+x%5E2s(x)
  19.  
  20. Step 2:
  21. k = x/(1 - x - x^2)
  22. https://www.wolframalpha.com/input/?i=solve+k+%3D+x%2F(1+-+x+-+x%5E2)+for+x
  23.  
  24. Step 3:
  25. b^2 = sqrt(5k^2 + 2k + 1)
  26.  
  27. Case 1, 2, 3, 5, 8, ...
  28. Step 1:
  29. s(x) = x + 2x^2 + x(s(x) - x) + x^2s(x)
  30. https://www.wolframalpha.com/input/?i=s(x)+%3D+x+%2B+2x%5E2+%2B+x(s(x)+-+x)+%2B+x%5E2s(x)
  31.  
  32. Step 2:
  33. k = (x^2 + x)/(1 - x - x^2)
  34. https://www.wolframalpha.com/input/?i=solve+k+%3D+(x%5E2+%2B+x)%2F(1+-+x+-+x%5E2)+for+x
  35.  
  36. Step 3:
  37. b^2 = sqrt(5k^2 + 6k + 1)
  38.  
  39. Case 1, 3, 4, 7, 11, ...
  40. Step 1:
  41. s(x) = x + 3x^2 + x(s(x) - x) + x^2s(x)
  42. https://www.wolframalpha.com/input/?i=s(x)+%3D+x+%2B+3x%5E2+%2B+x(s(x)+-+x)+%2B+x%5E2s(x)
  43.  
  44. Step 2:
  45. k = (2x^2 + x)/(1 - x - x^2)
  46. https://www.wolframalpha.com/input/?i=solve+k+%3D+(2x%5E2+%2B+x)%2F(1+-+x+-+x%5E2)+for+x
  47.  
  48. Step 3:
  49. b^2 = sqrt(5k^2 + 10k + 1)
  50.  
  51. Case 1, 4, 5, 9, 14, 23, ...
  52. Step 1:
  53. s(x) = x + 4x^2 + x(s(x) - x) + x^2s(x)
  54. https://www.wolframalpha.com/input/?i=s(x)+%3D+x+%2B+4x%5E2+%2B+x(s(x)+-+x)+%2B+x%5E2s(x)
  55.  
  56. Step 2:
  57. k = (3x^2 + x)/(1 - x - x^2)
  58. https://www.wolframalpha.com/input/?i=solve+k+%3D+(3x%5E2+%2B+x)%2F(1+-+x+-+x%5E2)+for+x
  59.  
  60. Step 3:
  61. b^2 = sqrt(5k^2 + 14k + 1)
  62. */
  63.  
  64. long long f() {
  65. long long k;
  66. mpz_t x, y;
  67.  
  68. //Init
  69. mpz_init(x);
  70. mpz_init(y);
  71.  
  72. for(k = 1; k < 1000000000; k++) {
  73. mpz_set_ui(x, 5);
  74. mpz_mul_ui(x, x, k);
  75. mpz_mul_ui(x, x, k);
  76.  
  77. //mpz_set_ui(y, 2);
  78. //mpz_set_ui(y, 6);
  79. //mpz_set_ui(y, 10);
  80. //mpz_set_ui(y, 14);
  81. mpz_set_ui(y, 16);
  82. mpz_mul_ui(y, y, k);
  83.  
  84. mpz_add(x, x, y);
  85. mpz_add_ui(x, x, 1);
  86.  
  87. if(mpz_perfect_square_p(x) == 1)
  88. cout << k << endl;
  89. }
  90.  
  91. return 0;
  92. }
  93.  
  94. int check(mpz_t x, mpz_t y, long long k, int s) {
  95. mpz_set_ui(x, 5);
  96. mpz_mul_ui(x, x, k);
  97. mpz_mul_ui(x, x, k);
  98.  
  99. mpz_set_ui(y, s);
  100. mpz_mul_ui(y, y, k);
  101.  
  102. mpz_add(x, x, y);
  103. mpz_add_ui(x, x, 1);
  104.  
  105. return mpz_perfect_square_p(x);
  106. }
  107.  
  108. /*
  109. Data:
  110. 3
  111. 6
  112. 30
  113. 51
  114. 216
  115. 360
  116. 1491
  117. 2478
  118. 10230
  119. 16995
  120. 70128
  121. 116496
  122. 480675
  123. 798486
  124. 3294606
  125. 5472915
  126. 22581576
  127. 37511928
  128. 154776435
  129. 257110590
  130. 1060853478
  131. 1762262211
  132. 7271197920
  133. 12078724896
  134. */
  135. long long f2() {
  136. long long k, m, s;
  137. mpz_t x, y;
  138.  
  139. //Init
  140. mpz_init(x);
  141. mpz_init(y);
  142. k = 2;
  143. m = 2;
  144. s = 0;
  145.  
  146. while(true) {
  147. if(check(x, y, k, 18) == 1) {
  148. cout << k << endl;
  149. //cout << k << " " << s << endl;
  150.  
  151. //k -= s;
  152. //k *= m;
  153.  
  154. //m = (m == 2) ? 183 : 2;
  155. //s = 0;
  156. }
  157.  
  158. k++;
  159. }
  160.  
  161. return 0;
  162. }
  163.  
  164. int main() {
  165. cout << "Result = " << f2() << endl;
  166.  
  167. return 0;
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement