当前位置:网站首页>Return the next higher prime number
Return the next higher prime number
2022-08-10 17:00:00 【小绵杨Yancy】
一、要求
This challenge is a little bit more complex
Write a function that takes a number (a) as argument
If a is prime, return a
If not, return the next higher prime number

二、解
function myFunction( a ) {
function isPrime(num) {
for (let i = 2; i <= Math.sqrt(num); i++) {
if (num % i === 0) return false;
}
return num > 1;
}
let n = a;
while (!isPrime(n)) n++;
return n
}
边栏推荐
猜你喜欢
随机推荐
C语言按位运算符如何使用
华为-求int型正整数在内存中存储时1的个数
C language symbols on how to use
ahx文件转mav文件 工具分享及说明
docker中安装mysql
Embedded Development: Embedded Basics - Mapping Peripherals Using Arrays of Pointers
MySQL增加字段SQL语句
电力系统潮流【牛顿-拉夫逊法】(4节点、5节点、6节点、9节点)(Matlab代码实现)
kuangbin专题一 简单搜索
险资又做LP,一出手40亿
8.9模拟赛总结
win11安装deepin20.6双系统(双硬盘)
PC软件问题二[Win10系统将UltraEdit添加到右键菜单的方法]
3 年 CRUD 从 8K 涨到 28K,谁知道这4个月我到底经历了什么?
fastjson chain analysis (1.2.22-47)
Trie字典树
v-show指令:切换元素的显示与隐藏
#夏日挑战赛#【ELT.ZIP】啃论文俱乐部——学术科研方法论沉淀辑
leetcode:339 嵌套列表权重和
vvic API 接入说明









