当前位置:网站首页>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
边栏推荐
- 最新高频Android面试题目分享,带你一起探究Android事件分发机制
- QT video transmission
- Master this promotion path and share interview materials
- The top of slashdata developer tool is up to you!!!
- Skimage learning (1)
- Flash build API service
- [fan Tan] those stories that seem to be thinking of the company but are actually very selfish (I: building wheels)
- 【饭谈】如何设计好一款测试平台?
- Sator推出Web3游戏“Satorspace” ,并上线Huobi
- mysql实现两个字段合并成一个字段查询
猜你喜欢
随机推荐
【Seaborn】组合图表:FacetGrid、JointGrid、PairGrid
浅浅理解.net core的路由
DNS 系列(一):为什么更新了 DNS 记录不生效?
Seaborn数据可视化
一文读懂数仓中的pg_stat
LeetCode 1654. The minimum number of jumps to get home one question per day
赋能智慧电力建设 | 麒麟信安高可用集群管理系统,保障用户关键业务连续性
LeetCode 300. Daily question of the longest increasing subsequence
如何选择合适的自动化测试工具?
Blue Bridge Cup final XOR conversion 100 points
Is AI more fair than people in the distribution of wealth? Research on multiplayer game from deepmind
Skimage learning (3) -- gamma and log contrast adjustment, histogram equalization, coloring gray images
[fan Tan] after the arrival of Web3.0, where should testers go? (ten predictions and suggestions)
Notes on installing MySQL in centos7
skimage学习(3)——使灰度滤镜适应 RGB 图像、免疫组化染色分离颜色、过滤区域最大值
最新阿里P7技术体系,妈妈再也不用担心我找工作了
LeetCode 1049. 最后一块石头的重量 II 每日一题
蓝桥杯 决赛 异或变换 100分
Leetcode brush questions day49
LeetCode 213. 打家劫舍 II 每日一题