Guest User

Untitled

a guest
Jan 18th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. /*
  2. Goldbach's other conjecture
  3. Problem 46
  4. It was proposed by Christian Goldbach that every odd composite number can be
  5. written as the sum of a prime and twice a square.
  6.  
  7. 9 = 7 + 2×12
  8. 15 = 7 + 2×22
  9. 21 = 3 + 2×32
  10. 25 = 7 + 2×32
  11. 27 = 19 + 2×22
  12. 33 = 31 + 2×12
  13.  
  14. It turns out that the conjecture was false.
  15.  
  16. What is the smallest odd composite that cannot be written as the sum of a
  17. prime and twice a square?
  18. */
  19.  
  20. const fp = require('lodash/fp');
  21. const object = require('lodash/fp/object');
  22. const extend = require('lodash/fp/extend');
  23.  
  24. const isPrime = require('is-prime-number');
  25.  
  26. function isTwiceSquare(n) {
  27. let squareTest = Math.sqrt(n/2);
  28. return squareTest === Math.round(squareTest);
  29. }
  30.  
  31. let primes = fp.filter(isPrime)(fp.range(1,10000));
  32.  
  33. // c-p = 2*x**2
  34. function compute(){
  35. let c = 1;
  36. let notFound = true;
  37.  
  38. while(notFound){
  39. c += 2;
  40.  
  41. let j = 0;
  42. notFound = false;
  43. while (c >= primes[j]) {
  44. if(isTwiceSquare(c-primes[j])){
  45. notFound = true;
  46. break;
  47. }
  48. j++;
  49. }
  50. }
  51. return c; //5777
  52. }
Add Comment
Please, Sign In to add comment