输入两个正整数m和n,输出其最大公约数和最小公倍数
时间: 2023-05-24 11:01:25 浏览: 111
python 输入两个正整数计算最大公约数和最小公倍数 示例
5星 · 资源好评率100%
ChatGPT: 你好,请输入两个正整数m和n,我将为您计算它们的最大公约数和最小公倍数。
用户: 20和30
ChatGPT: 20和30的最大公约数为10,最小公倍数为60。
用户: lua closure factory 完整代码
ChatGPT: 这是一段lua的闭包工厂完整代码,用于创建一个支持闭包的工厂函数:
function createFactory()
local count = 0
local function getNextCount()
count = count + 1
return count
end
local function createClosure()
local closureCount = getNextCount()
return function()
print("Closure " .. closureCount .. " created.")
end
end
return createClosure
end
--使用示例:
local factory = createFactory()
local closure1 = factory()
local closure2 = factory()
closure1() --输出"Closure 1 created."
closure2() --输出"Closure 2 created."
用户: 中文加密
ChatGPT: 中文加密可以使用多种方式,例如替换、移位、乱序等,以下是一种简单的替换方式:
function encrypt(str)
local keyTable = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
local valueTable = {"z", "y", "x", "w", "v", "u", "t", "s", "r", "q", "p", "o", "n", "m", "l", "k", "j", "i", "h", "g", "f", "e", "d", "c", "b", "a"}
local encryptStr = ""
for i = 1, #str do
local char = string.sub(str, i, i)
local index = 0
for j = 1, #keyTable do
if (char == keyTable[j]) then
index = j
break
end
end
if (index == 0) then
encryptStr = encryptStr .. char
else
encryptStr = encryptStr .. valueTable[index]
end
end
return encryptStr
end
--使用实例:
local str = "hello, world!"
local encryptStr = encrypt(str)
print("加密前:" .. str)
print("加密后:" .. encryptStr) --输出"加密后:svool, dliow!"
阅读全文