当前位置:网站首页>JS to print prime numbers between 1-100 and calculate the total number of optimized versions
JS to print prime numbers between 1-100 and calculate the total number of optimized versions
2022-06-27 07:35:00 【I am the sun?】
Code :
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<script type="text/javascript">
var sum = 0;
for(var i = 1;i <= 100;i++){
var flag = true;
if(i == 1)
flag = false;
for(var j = 2;j <= Math.sqrt(i);j++){
if(i % j == 0){
flag = false;
break;
}
}
if(flag){
document.write(i + " ");
sum++;
}
}
document.write("<br /> Primes in all :" + sum + " individual .");
</script>
</head>
<body>
</body>
</html>
The operation results are as follows :
explain :

In terms of mathematical factors :
4 The factors that affect it are :14,22
therefore , Count to 2,4 It can be disassembled into 2 了 , You should quit
Empathy :
9 The factors that affect it are :19,33
therefore , Count to 3, You can quit
Empathy :
36 The factors that affect it are :136,218,312,49,66. The biggest is 66
Count to , Even the largest 6*6 You have to quit
therefore , The number after square root is rounded , You have to quit . It saves a lot of time .
边栏推荐
- Interviewer: please introduce cache penetration, cache null value, cache avalanche and cache breakdown, which are easy to understand
- Guava tutorial collect some cases and write Google tool classes slowly
- 2022 cisp-pte (II) SQL injection
- 2. QT components used in the project
- Win10 remote connection to ECS
- Delay queue `delayqueue`
- (resolved) NPM suddenly reports an error cannot find module 'd:\program files\nodejs\node_ modules\npm\bin\npm-cli. js‘
- volatile 和 synchronized 到底啥区别?
- hutool对称加密
- boundvalueops和opsforvalue区别
猜你喜欢

2、项目使用的QT组件

Interviewer: please introduce cache penetration, cache null value, cache avalanche and cache breakdown, which are easy to understand

Multi table associated query -- 07 -- hash join

Configuring FTP, enterprise official website, database and other methods for ECS

Error in idea connection database

Goodbye, agile Scrum

js用while循环计算假如投资多年的利率为5%,试求从1000块增长到5000块,需要花费多少年

yarn create vite 报错 ‘D:\Program‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件

js中输入三个值,并且由小到大输出

Win10 remote connection to ECS
随机推荐
Common operation and Principle Exploration of stream
Jupiter notebook file directory
How to add data to the back-end database in the form of Excel file on the web page
[graduation season] graduation is the new beginning of your life journey. Are you ready
磁选机是什么?
将通讯录功能设置为数据库维护,增加用户名和密码
Cookie encryption 6
Difference between boundvalueops and opsforvalue
Installation and functions of uview
log4j:WARN No such property [zipPermission] in org. apache. log4j. RollingFileAppender.
用XGBoost迭代读取数据集
guava 定时任务
语音信号处理-概念(二):幅度谱(短时傅里叶变换谱/STFT spectrum)、梅尔谱(Mel spectrum)【语音的深度学习主要用幅度谱、梅尔谱】【用librosa或torchaudio提取】
Yarn create vite reports an error 'd:\program' which is neither an internal or external command nor a runnable program or batch file
通过uview让tabbar根据权限显示相应数量的tabbar
The song of cactus -- throwing stones to ask the way (1)
Interviewer: how to never migrate data and avoid hot issues by using sub database and sub table?
Xiaomi Interviewer: let's talk about the proficient Registration Center for three days and three nights
Bean copy details
How to bind SQL statements to web buttons