当前位置:网站首页>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 .
边栏推荐
猜你喜欢

语音信号特征提取流程:输入语音信号-分帧、预加重、加窗、FFT->STFT谱(包括幅度、相位)-对复数取平方值->幅度谱-Mel滤波->梅尔谱-取对数->对数梅尔谱-DCT->FBank->MFCC

Process termination (have you really learned recursion? Test your recursion Foundation)

一个人管理1000台服务器?这款自动化运维工具一定要掌握

VNC Viewer方式的远程连接树莓派

Error in idea connection database

js输出1-100之间所有的质数并求总个数

Solve the problem of win10 wsl2 IP change

js打印99乘法表

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

mssql如何使用语句导出并删除多表数据
随机推荐
js中如何查看程序运行时间(计时器)
Interviewer: how to never migrate data and avoid hot issues by using sub database and sub table?
语音合成:Tacotron详解【端到端语音合成模型】【与传统语音合成相比,它没有复杂的语音学和声学特征模块,而是仅用<文本序列,语音声谱>配对数据集对神经网络进行训练,因此简化了很多流程】
Use uview to enable tabbar to display the corresponding number of tabbars according to permissions
语音信号处理-概念(一):时谱图(横轴:时间;纵轴:幅值)、频谱图(横轴:频率;纵轴:幅值)--傅里叶变换-->时频谱图【横轴:时间;纵轴:频率;颜色深浅:幅值】
manim 数学引擎
Talk about Domain Driven Design
R language analyzing wine data
Process termination (have you really learned recursion? Test your recursion Foundation)
[leetcode] day90 the element with the smallest K in the binary search tree
Win10 remote connection to ECS
[openairinterface5g] rrcsetupcomplete for RRC NR resolution
Interviewer: do you have any plan to request a lot of data that does not exist in redis to destroy the database?
专业四第二周自测
Custom palette for ggplot2
How to implement redis cache of highly paid programmers & interview questions series 116? How do I find a hot key? What are the possible problems with caching?
用XGBoost迭代读取数据集
js成绩奖惩例题
File 与 MultipartFile概述
js用switch输出成绩是否合格