当前位置:网站首页>L1-028 judging prime number (Lua)
L1-028 judging prime number (Lua)
2022-07-07 19:17:00 【Just be interesting】
subject
The goal of this question is very simple , Is to determine whether a given positive integer is a prime number .
Input format :
Enter a positive integer on the first line N(≤ 10), And then N That's ok , Each line gives a less than 2
31
A positive integer that needs to be judged .
Output format :
For each positive integer to be judged , If it's a prime , Output in one line Yes, Otherwise output No.
sample input :
2
11
111
sample output :
Yes
No
Code
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
边栏推荐
- Multimodal point cloud fusion and visual location based on image and laser
- Redis集群与扩展
- SD_ DATA_ SEND_ SHIFT_ REGISTER
- SlashData开发者工具榜首等你而定!!!
- [HDU] 5248 sequence transformation (greedy + dichotomy) [recommended collection]
- 反爬虫的重点:识别爬虫
- 二叉树的基本概念和性质
- Interview vipshop internship testing post, Tiktok internship testing post [true submission]
- Business experience in virtual digital human
- Former richest man, addicted to farming
猜你喜欢
前首富,沉迷种田
如何选择合适的自动化测试工具?
抢占周杰伦
Redis
99% of people don't know that privatized deployment is also a permanently free instant messaging software!
Version 2.0 of tapdata, the open source live data platform, has been released
二叉树的基本概念和性质
Three forms of multimedia technology commonly used in enterprise exhibition hall design
Complete e-commerce system
Antisamy: a solution against XSS attack tutorial
随机推荐
Complete e-commerce system
Continuous test (CT) practical experience sharing
2022上半年朋友圈都在传的10本书,找到了
POJ 2392 Space Elevator
99% of people don't know that privatized deployment is also a permanently free instant messaging software!
Pasqal首席技术官:模拟量子计算率先为工业带来量子优势
Former richest man, addicted to farming
Desci: is decentralized science the new trend of Web3.0?
炒股如何开户?请问一下手机开户股票开户安全吗?
A hodgepodge of ICER knowledge points (attached with a large number of topics, which are constantly being updated)
Chief technology officer of Pasqual: analog quantum computing takes the lead in bringing quantum advantages to industry
杰理之测试盒配置声道【篇】
Realize payment function in applet
Interview vipshop internship testing post, Tiktok internship testing post [true submission]
3. About cookies
2022.07.05
学习open62541 --- [67] 添加自定义Enum并显示名字
Key points of anti reptile: identifying reptiles
Redis cluster and expansion
State mode - Unity (finite state machine)