当前位置:网站首页>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
边栏推荐
- Classification and application of enterprise MES Manufacturing Execution System
- 2022.07.02
- Multimodal point cloud fusion and visual location based on image and laser
- Complete e-commerce system
- 学习open62541 --- [67] 添加自定义Enum并显示名字
- Embedded interview questions (algorithm part)
- UVALive – 4621 Cav 贪心 + 分析「建议收藏」
- testing and SQA_动态白盒測试[通俗易懂]
- L1-019 who falls first (Lua)
- 6.关于jwt
猜你喜欢
随机推荐
Golang client server login
First time in China! The language AI strength of this Chinese enterprise is recognized as No.2 in the world! Second only to Google
Basic operation of chain binary tree (implemented in C language)
网易云信参与中国信通院《实时音视频服务(RTC)基础能力要求及评估方法》标准编制...
抢占周杰伦
Numpy——2.数组的形状
Key points of anti reptile: identifying reptiles
[HDU] 5248 sequence transformation (greedy + dichotomy) [recommended collection]
如何给“不卖笔”的晨光估值?
高温火烧浑不怕,钟薛高想留清白在人间
我感觉被骗了,微信内测 “大小号” 功能,同一手机号可注册两个微信
[information security laws and regulations] review
2022.07.02
Seize Jay Chou
Command mode - unity
testing and SQA_动态白盒測试[通俗易懂]
Three forms of multimedia technology commonly used in enterprise exhibition hall design
SD_ DATA_ SEND_ SHIFT_ REGISTER
Big Ben (Lua)
杰理之相同声道的耳机不允许配对【篇】
![[tpm2.0 principle and Application guide] Chapter 16, 17 and 18](/img/7a/b16549590e6445d9199c8000d47d36.png)


![[information security laws and regulations] review](/img/da/c9318ea8999c3ee629b0e48ab78581.png)



![学习open62541 --- [67] 添加自定义Enum并显示名字](/img/98/e5e25af90b3f98c2be11d7d21e5ea6.png)

