x_neg_k.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // a(n) is the least integer k > 2 such that the remainder of -k modulo p is strictly increasing over the first n primes.
  2. // https://oeis.org/A306612
  3. // a(16) = 118867612
  4. // a(17) = 4968215191
  5. // a(18) = 31090893772
  6. // a(19) = 118903377091
  7. #include <set>
  8. #include <iostream>
  9. #include <vector>
  10. #include <algorithm>
  11. using namespace std;
  12. int main() {
  13. long long int p = 71;
  14. long long int primes[19] = {67, 61, 59, 53, 47, 43, 41, 37, 31, 29, 23, 19, 17, 13, 11, 7, 5, 3, 2};
  15. for ( long long int k = 118903377091LL; ; ++k) {
  16. //cout << k << endl;
  17. auto max = (-k) % p;
  18. //cout << max << " -- " << max + p << endl;
  19. if (max < 0) {
  20. max += p;
  21. }
  22. bool ok = true;
  23. //cout << max << endl;
  24. for (auto q : primes) {
  25. auto t = (-k) % q;
  26. if (t < 0) {
  27. t += q;
  28. }
  29. if (t < max) {
  30. max = t;
  31. }
  32. else {
  33. ok = false;
  34. break;
  35. }
  36. }
  37. if (ok) {
  38. cout << "Found\n";
  39. cout << k << "\n";
  40. break;
  41. }
  42. }
  43. }