当前位置:网站首页>L1-028 判断素数(Lua)
L1-028 判断素数(Lua)
2022-07-07 15:38:00 【有趣就行】
题目
本题的目标很简单,就是判断一个给定的正整数是否素数。
输入格式:
输入在第一行给出一个正整数N(≤ 10),随后N行,每行给出一个小于2
31
的需要判断的正整数。
输出格式:
对每个需要判断的正整数,如果它是素数,则在一行中输出Yes,否则输出No。
输入样例:
2
11
111
输出样例:
Yes
No
代码
function isPrime(x)
if x == 0 or x == 1 then
return false
end
local i = 2
while i <= x / i do
if x % i == 0 then
return false
end
i = i + 1
end
return true
end
local n = io.read()
for i = 1, n do
local num = tonumber(io.read())
if isPrime(num) then
print("Yes")
else
print("No")
end
end
边栏推荐
- mysql实现两个字段合并成一个字段查询
- LeetCode 1654. The minimum number of jumps to get home one question per day
- LeetCode 312. 戳气球 每日一题
- QT中自定义控件的创建到封装到工具栏过程(一):自定义控件的创建
- 最新高频Android面试题目分享,带你一起探究Android事件分发机制
- Module VI
- [Seaborn] combination chart: pairplot and jointplot
- 麒麟信安操作系统衍生产品解决方案 | 存储多路径管理系统,有效提高数据传输可靠性
- LeetCode 1043. 分隔数组以得到最大和 每日一题
- Skimage learning (3) -- gamma and log contrast adjustment, histogram equalization, coloring gray images
猜你喜欢

MRS离线数据分析:通过Flink作业处理OBS数据

How to choose the appropriate automated testing tools?

skimage学习(3)——Gamma 和 log对比度调整、直方图均衡、为灰度图像着色

鲲鹏开发者峰会2022 | 麒麟信安携手鲲鹏共筑计算产业新生态
![[Seaborn] combination chart: facetgrid, jointgrid, pairgrid](/img/89/a7cf40fb3a7622cb78ea1b92ffd2fb.png)
[Seaborn] combination chart: facetgrid, jointgrid, pairgrid

Leetcode brush questions day49

Sator launched Web3 game "satorspace" and launched hoobi

Linux 安装mysql8.X超详细图文教程

麒麟信安携异构融合云金融信创解决方案亮相第十五届湖南地区金融科技交流会
最新高频Android面试题目分享,带你一起探究Android事件分发机制
随机推荐
QT video transmission
centos7安装mysql笔记
最新阿里P7技术体系,妈妈再也不用担心我找工作了
Flask搭建api服务-SQL配置文件
Read PG in data warehouse in one article_ stat
浅谈 Apache Doris FE 处理查询 SQL 源码解析
【视频/音频数据处理】上海道宁为您带来Elecard下载、试用、教程
LeetCode刷题day49
[fan Tan] after the arrival of Web3.0, where should testers go? (ten predictions and suggestions)
DNS series (I): why does the updated DNS record not take effect?
[Huang ah code] Why do I suggest you choose go instead of PHP?
rpcms获取指定分类下的文章的方法
LeetCode 152. Product maximum subarray daily question
skimage学习(3)——使灰度滤镜适应 RGB 图像、免疫组化染色分离颜色、过滤区域最大值
管理VDI的几个最佳实践
[source code interpretation] | source code interpretation of livelistenerbus
Notes on installing MySQL in centos7
MySQL usage notes 1
Sator推出Web3游戏“Satorspace” ,并上线Huobi
LeetCode 403. 青蛙过河 每日一题