zoukankan      html  css  js  c++  java
  • 运动算法--整数被分成素数的乘积

    问题:

    进入6

    出口 1*2*3


    1. build素数表

    2. 从质数的序列中取素数列表,n除了黄金,这个假设是不能分开的,素数表索引++,除此以外,n/=素数,继续推理

    3. 特拉弗斯素表

    4. 有限性:须要足够大 ,假设数字很大,此算法须要改变


    JS 实现:


    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(;pIndex<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));
    
    




  • 相关阅读:
    apache安装 mod_evasive
    sshd调优
    MySQL服务器状态变量
    MySQL查询缓存
    MySQL并发调优和IO调优
    MySQL线程独享[转]
    mysql线程缓存和表缓存
    MySQL点滴
    MySQL优化常用
    apache的prefork的详解
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/4605504.html
Copyright © 2011-2022 走看看