xxxxxxxxxx
81
function setup() {
noCanvas();
var x = semiPrimeFactors(666)[0];
var y = semiPrimeFactors(666)[1];
console.log(x, y);
}
function draw() {
frameRate(10);
// console.log(A000001(3125));
}
function A000001(n) {
if (n == 16) {
return 14;
}
if (n == 32) {
return 51;
}
if (n == 243) {
return 67;
}
if (isPrime(n)) {
return 1;
}
const squareRoot = sqrt(n);
const cubeRoot = pow(n, 1 / 3);
const fourthRoot = sqrt(squareRoot);
const fifthRoot = pow(n, 1 / 5);
if ((squareRoot % 1 == 0) && isPrime(squareRoot)) {
return 2;
}
if ((cubeRoot % 1 == 0) && isPrime(cubeRoot)) {
return 5;
}
if ((fourthRoot % 1 == 0) && isPrime(fourthRoot)) {
return 15;
}
if ((fifthRoot % 1 == 0) && isPrime(fifthRoot)) {
return 61 + 2 * n + 2 * gcd(n - 1, 3) + gcd(n - 1, 4);
}
}
function isPrime(n) {
if (n <= 1) {
return false;
}
if (n <= 3) {
return true;
}
if (n % 2 == 0 || n % 3 == 0) {
return false;
}
for (let i = 5; i <= ceil(sqrt(n)); i += 6) {
if (n % i == 0 || n % (i + 2) == 0)
return false;
}
return true;
}
function gcd(a, b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
function semiPrimeFactors(n) {
let d2;
for (let d1 = 2; d1 < int(sqrt(n)) + 1; d1++) {
if (n % d1 == 0) {
d2 = n / d1;
if (isPrime(d1) && isPrime(d2)) {
return [d1, d2];
}
}
}
return [undefined, undefined];
}