当前位置:网站首页>L1-028 判断素数(Lua)
L1-028 判断素数(Lua)
2022-07-07 15:38:00 【有趣就行】
题目
本题的目标很简单,就是判断一个给定的正整数是否素数。
输入格式:
输入在第一行给出一个正整数N(≤ 10),随后N行,每行给出一个小于2
31
的需要判断的正整数。
输出格式:
对每个需要判断的正整数,如果它是素数,则在一行中输出Yes,否则输出No。
输入样例:
2
11
111
输出样例:
Yes
No
代码
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
边栏推荐
- First in China! Todesk integrates RTC technology into remote desktop, with clearer image quality and smoother operation
- 第九届 蓝桥杯 决赛 交换次数
- Matplotlib绘图界面设置
- LeetCode 403. 青蛙过河 每日一题
- 《产品经理必读:五种经典的创新思维模型》的读后感
- 【源码解读】| LiveListenerBus源码解读
- Proxmox VE重装后,如何无损挂载原有的数据盘?
- LeetCode 300. 最长递增子序列 每日一题
- LeetCode 1031. 两个非重叠子数组的最大和 每日一题
- Nerf: the ultimate replacement for deepfake?
猜你喜欢

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

麒麟信安携异构融合云金融信创解决方案亮相第十五届湖南地区金融科技交流会

NeRF:DeepFake的最终替代者?

Nerf: the ultimate replacement for deepfake?

How to add aplayer music player in blog

skimage学习(2)——RGB转灰度、RGB 转 HSV、直方图匹配

Sator推出Web3游戏“Satorspace” ,并上线Huobi

Matplotlib绘图界面设置

SlashData开发者工具榜首等你而定!!!

Test case management tool recommendation
随机推荐
Leetcode brush questions day49
LeetCode 1186. Delete once to get the sub array maximum and daily question
Linux 安装mysql8.X超详细图文教程
Skimage learning (3) -- gamma and log contrast adjustment, histogram equalization, coloring gray images
LeetCode 152. Product maximum subarray daily question
第九届 蓝桥杯 决赛 交换次数
Matplotlib绘图界面设置
DNS series (I): why does the updated DNS record not take effect?
Sator launched Web3 game "satorspace" and launched hoobi
【饭谈】如何设计好一款测试平台?
AI来搞财富分配比人更公平?来自DeepMind的多人博弈游戏研究
First in China! Todesk integrates RTC technology into remote desktop, with clearer image quality and smoother operation
蓝桥杯 决赛 异或变换 100分
【饭谈】Web3.0到来后,测试人员该何去何从?(十条预言和建议)
LeetCode 1049. Weight of the last stone II daily question
Rpcms method of obtaining articles under the specified classification
[Seaborn] combination chart: pairplot and jointplot
LeetCode刷题day49
Sator a lancé le jeu web 3 "satorspace" et a lancé huobi
Repair method of firewall system crash and file loss, material cost 0 yuan