Online Lemoine’s Conjecture Demo


Lemoine’s Conjecture says any odd integer greater than 5 can be represented as the sum of an odd prime number and an even semiprime. Another statement which is suitable for programming is that 2n + 1 = p + 2q always has a solution in primes p and q (not necessarily distinct) for n > 2. This online demo will find p and q for given odd number greater than 5.

Input Odd Number Greater Than 5:



Source Code (HTML)

Input Odd Number Greater Than 5: <input type="text" name="n"><br><br>
<button type="button" id="getLemoine">Get Lemoine’s Conjecture</button><br><br>
<textarea id="result" rows="20" cols="50"></textarea>

Source Code (JavaScript)

var elmn = document.querySelector("input[name='n']");
var btn = document.querySelector("#getLemoine");
var resultElm = document.querySelector("#result");
btn.addEventListener("click", function(e) {
  var n = parseInt(elmn.value);
  if (!Number.isInteger(n)) {
    resultElm.value = "input must be integer!";
    return;
  }
  if ( n<=5 || n%2 == 0) {
    resultElm.value = "n must be greater than 5 and must be odd!";
    return;
  }
  Lemoine(n);
});

function IsPrime(n) {
  if (n<2) {
    return false;
  }

  var i;
  for (i = 2; i*i <= n; i++) {
      if (n%i == 0) {return false;}
  }
  return true;
}

function Lemoine(n) {
      var pqPairs = {};

      var q;
      for (q = 1; q <= n/2; q++) {
              var p = n - 2*q;

              if (IsPrime(p) && IsPrime(q)) {
                      pqPairs[p] = q;
              }
      }

      resultElm.value = "";
      for (var p in pqPairs) {
              var q = pqPairs[p];
              resultElm.value += (n.toString() + " = " + p.toString() + " + ( 2 * " + q.toString() + " ) \n");
      }
}

Tested on: Chromium 65.0.3325.181 on Ubuntu 17.10 (64-bit)


References:

[1]Lemoine’s Conjecture