当前位置:网站首页>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
边栏推荐
- LeetCode 120. 三角形最小路径和 每日一题
- SIGGRAPH 2022最佳技术论文奖重磅出炉!北大陈宝权团队获荣誉提名
- 一文读懂数仓中的pg_stat
- 测试用例管理工具推荐
- Localstorage and sessionstorage
- 国内首创!Todesk将RTC技术融入远程桌面,画质更清晰操作更流畅
- The process of creating custom controls in QT to encapsulating them into toolbars (II): encapsulating custom controls into toolbars
- [Seaborn] implementation of combined charts and multi subgraphs
- Biped robot controlled by Arduino
- mysql使用笔记一
猜你喜欢
Master this promotion path and share interview materials
麒麟信安加入宁夏商用密码协会
《产品经理必读:五种经典的创新思维模型》的读后感
[video / audio data processing] Shanghai daoning brings you elecard download, trial and tutorial
LeetCode刷题day49
NeRF:DeepFake的最终替代者?
QML beginner
浅浅理解.net core的路由
SlashData开发者工具榜首等你而定!!!
Skimage learning (2) -- RGB to grayscale, RGB to HSV, histogram matching
随机推荐
LeetCode 1774. 最接近目标价格的甜点成本 每日一题
Reflections on "product managers must read: five classic innovative thinking models"
Sator a lancé le jeu web 3 "satorspace" et a lancé huobi
LeetCode 312. Poke balloon daily
Biped robot controlled by Arduino
LeetCode 1477. Find two subarrays with sum as the target value and no overlap
The server is completely broken and cannot be repaired. How to use backup to restore it into a virtual machine without damage?
【Seaborn】组合图表、多子图的实现
如何在软件研发阶段落地安全实践
【源码解读】| LiveListenerBus源码解读
最新阿里P7技术体系,妈妈再也不用担心我找工作了
Seaborn data visualization
LeetCode 300. Daily question of the longest increasing subsequence
[Huang ah code] Why do I suggest you choose go instead of PHP?
LeetCode 1986. 完成任务的最少工作时间段 每日一题
LeetCode 1654. The minimum number of jumps to get home one question per day
邮件服务器被列入黑名单,如何快速解封?
第九届 蓝桥杯 决赛 交换次数
99% of users often make mistakes in power Bi cloud reports
QT 图片背景色像素处理法