当前位置:网站首页>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
边栏推荐
- Longest common prefix (leetcode question 14)
- UVALive – 4621 Cav 贪心 + 分析「建议收藏」
- Golang client server login
- coming! Gaussdb (for Cassandra) new features appear
- SlashData开发者工具榜首等你而定!!!
- Redis集群与扩展
- Multimodal point cloud fusion and visual location based on image and laser
- Review of network attack and defense
- POJ 1182 :食物链(并查集)[通俗易懂]
- POJ 2392 Space Elevator
猜你喜欢
随机推荐
2022-07-04 matlab读取视频帧并保存
unity2d的Rigidbody2D的MovePosition函数移动时人物或屏幕抖动问题解决
SlashData开发者工具榜首等你而定!!!
Short selling, overprinting and stock keeping, Oriental selection actually sold 2.66 million books in Tiktok in one month
如何选择合适的自动化测试工具?
前首富,沉迷种田
Chief technology officer of Pasqual: analog quantum computing takes the lead in bringing quantum advantages to industry
鸿蒙智能家居【1.0】
RISCV64
学习open62541 --- [67] 添加自定义Enum并显示名字
SD_ DATA_ SEND_ SHIFT_ REGISTER
PTA 1101 B是A的多少倍
Uvalive – 4621 CAV greed + analysis "suggestions collection"
【HDU】5248-序列变换(贪心+二分)「建议收藏」
Thread factory in thread pool
Golang client server login
Key points of anti reptile: identifying reptiles
Basic operation of chain binary tree (implemented in C language)
LeetCode 497(C#)
How much does it cost to develop a small program mall?







![[tpm2.0 principle and Application guide] Chapter 9, 10 and 11](/img/7f/0d4d91142bc3d79ea445a8f64afba7.png)

