当前位置:网站首页>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
边栏推荐
- Command mode - unity
- Classification and application of enterprise MES Manufacturing Execution System
- 99% of people don't know that privatized deployment is also a permanently free instant messaging software!
- How to share the same storage among multiple kubernetes clusters
- 基于图像和激光的多模态点云融合与视觉定位
- 初识缓存以及ehcache初体验「建议收藏」
- Chief technology officer of Pasqual: analog quantum computing takes the lead in bringing quantum advantages to industry
- 2022上半年朋友圈都在传的10本书,找到了
- Uvalive – 4621 CAV greed + analysis "suggestions collection"
- 數據驗證框架 Apache BVal 再使用
猜你喜欢
[tpm2.0 principle and Application guide] Chapter 9, 10 and 11
Numpy——axis
如何给“不卖笔”的晨光估值?
如何选择合适的自动化测试工具?
Will low code help enterprises' digital transformation make programmers unemployed?
In the first half of 2022, I found 10 books that have been passed around by my circle of friends
Three forms of multimedia technology commonly used in enterprise exhibition hall design
5billion, another master fund was born in Fujian
Continuous test (CT) practical experience sharing
微信网页调试8.0.19换掉X5内核,改用xweb,所以x5调试方式已经不能用了,现在有了解决方案
随机推荐
Chief technology officer of Pasqual: analog quantum computing takes the lead in bringing quantum advantages to industry
Classification and application of enterprise MES Manufacturing Execution System
解决远程rviz报错问题
鸿蒙智能家居【1.0】
POJ 1182: food chain (parallel search) [easy to understand]
Former richest man, addicted to farming
First time in China! The language AI strength of this Chinese enterprise is recognized as No.2 in the world! Second only to Google
Cadre de validation des données Apache bval réutilisé
基于图像和激光的多模态点云融合与视觉定位
Number - number (Lua)
6. About JWT
Numpy——axis
Scientists have observed for the first time that the "electron vortex" helps to design more efficient electronic products
2022上半年朋友圈都在传的10本书,找到了
How much does it cost to develop a small program mall?
Is AI more fair than people in the distribution of wealth? Research on multiplayer game from deepmind
POJ 1182 :食物链(并查集)[通俗易懂]
10 schemes to ensure interface data security
coming! Gaussdb (for Cassandra) new features appear
Comparison and selection of kubernetes Devops CD Tools