当前位置:网站首页>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
边栏推荐
- 解决rosdep的报错问题
- The moveposition function of rigidbody2d of unity2d solves the problem of people or screen jitter when moving
- 编译原理 实验一:词法分析器的自动实现(Lex词法分析)
- 博睿数据入选《2022爱分析 · IT运维厂商全景报告》
- 链式二叉树的基本操作(C语言实现)
- Initial experience of cache and ehcache "suggestions collection"
- LeetCode 890(C#)
- Redis集群与扩展
- State mode - Unity (finite state machine)
- [Base64 notes] [suggestions collection]
猜你喜欢

微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹

2022.07.02

Redis cluster and expansion

基于图像和激光的多模态点云融合与视觉定位

虚拟数字人里的生意经

高温火烧浑不怕,钟薛高想留清白在人间

Antisamy: a solution against XSS attack tutorial

Mathematical analysis_ Notes_ Chapter 11: Fourier series

如何选择合适的自动化测试工具?

Micro service remote debug, nocalhost + rainbow micro service development second bullet
随机推荐
Tips and tricks of image segmentation summarized from 39 Kabul competitions
POJ 2392 Space Elevator
unity2d的Rigidbody2D的MovePosition函数移动时人物或屏幕抖动问题解决
PTA 1102 教超冠军卷
LeetCode1051(C#)
二叉树的基本概念和性质
Key points of anti reptile: identifying reptiles
Interview vipshop internship testing post, Tiktok internship testing post [true submission]
Numpy——2.数组的形状
Is AI more fair than people in the distribution of wealth? Research on multiplayer game from deepmind
[software test] from the direct employment of the boss of the enterprise version, looking at the resume, there is a reason why you are not covered
Three forms of multimedia technology commonly used in enterprise exhibition hall design
【HDU】5248-序列变换(贪心+二分)「建议收藏」
Desci: is decentralized science the new trend of Web3.0?
Number - number (Lua)
Redis cluster and expansion
ES6笔记一
LeetCode 890(C#)
How to choose the appropriate automated testing tools?
For friends who are not fat at all, nature tells you the reason: it is a genetic mutation