Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Goldbach's other conjecture
- Problem 46
- It was proposed by Christian Goldbach that every odd composite number can be
- written as the sum of a prime and twice a square.
- 9 = 7 + 2×12
- 15 = 7 + 2×22
- 21 = 3 + 2×32
- 25 = 7 + 2×32
- 27 = 19 + 2×22
- 33 = 31 + 2×12
- It turns out that the conjecture was false.
- What is the smallest odd composite that cannot be written as the sum of a
- prime and twice a square?
- */
- const fp = require('lodash/fp');
- const object = require('lodash/fp/object');
- const extend = require('lodash/fp/extend');
- const isPrime = require('is-prime-number');
- function isTwiceSquare(n) {
- let squareTest = Math.sqrt(n/2);
- return squareTest === Math.round(squareTest);
- }
- let primes = fp.filter(isPrime)(fp.range(1,10000));
- // c-p = 2*x**2
- function compute(){
- let c = 1;
- let notFound = true;
- while(notFound){
- c += 2;
- let j = 0;
- notFound = false;
- while (c >= primes[j]) {
- if(isTwiceSquare(c-primes[j])){
- notFound = true;
- break;
- }
- j++;
- }
- }
- return c; //5777
- }
Add Comment
Please, Sign In to add comment