Problem:
Input 6
Output 1*2*3
1. List of build primes
2. From the Prime table in order to take prime numbers, N in addition to prime numbers, if not divisible, the Prime table index + +, otherwise, n/= Prime, continue to judge
3. Ergodic Prime List
4. Limited: The prime table needs to be large enough, if the number is very large, this algorithm needs to change
JS implementation:
function P (n) {if (n<2) {return 0;} if (n = = 2) {return 1;} for (var i = 2; i < n; i++) {if (n%i = = 0) {return 0;}} return 1;} var pl = new Array (), for (var i = 2,index = 0;index<100;i++) {if (P (i) = = 1) {Pl.push (i); index++;}} function f (n) {var pindex = 0;var ret = "1"; for (;p index<100;) {if (n% pl[pindex] = = 0) {ret + = "*" + pl[pindex]; n/=pl[pindex];} Else{if (P (n)) {ret + = "*" + n;return ret;} Pindex + +;}} return ret;} Console.log (f (111223));
Algorithm exercise-integer splitting into prime product