小编ahh*_*sad的帖子

素数因子和JavaScript

我坚持使用我用来解决问题的JavaScript代码:

13195的主要因素是5,7,13和29. 600851475143中最大的素数是多少?

(这不是作业,是在线编码/数学挑战)

所以我提出了这个解决方案:

<html>
    <head>
    <script type="text/javascript">

        // This function checks whether it's possible to divide the prime number
        function al(n){
            // k = 13195 is the number that I have to find the prime factor for
            var k = 13195;
            if (k%n) {
                return;
            }
            else {
                document.write(n + '   ');
            }
        }
    </script>
    </head>
    <body>
    <script type="text/javascript">

        //a and b are just for counting from the number n to 2 to find the prime numbers
        var …
Run Code Online (Sandbox Code Playgroud)

javascript primes

1
推荐指数
1
解决办法
7294
查看次数

标签 统计

javascript ×1

primes ×1