求x,y

--[[
x, y ∈ [1,9]
10x + y = a,
a^3 = c,是4位数
a^4 = d, 是6位数
c、d各数字正好是0~9中一个, 不重复
求x,y
]]
local Aarr = {}
for a=11,99 do
	if(1000<=a*a*a and a*a*a<=9999)then
		if(100000<=a*a*a*a and a*a*a*a <=999999)then
			table.insert(Aarr,a)
			--print(a)
		end
	end
end

--是否有重复
function isSame(arr)
	local tempArr = {}
	for k,v in pairs(arr)do
		tempArr[v] = v
	end

	local tempLen = 0
	for k,v in pairs(tempArr)do
		tempLen = tempLen + 1
	end
	if(#arr ~= tempLen)then
		return true
	end
	return false
end

function GetXYByA(a)
	for x=1,9 do
		for y=1,9 do
			if(10*x+y==a)then
				print("x=",x,"y=",y)
			end
		end
	end
end

for k,a in pairs(Aarr)do
	local arr = {}
	c=a*a*a
	q = math.modf(c/1000)
	b = math.modf(c%1000 /100)
	s = math.modf(c%100 /10)
	g = math.modf(c%10)
	d= c*a
	sw = math.modf(d/100000)
	w = math.modf(d%100000 /10000)
	qq = math.modf(d%10000 /1000)
	bb = math.modf(d%1000 /100)
	ss = math.modf(d%100 /10)
	gg = math.modf(d%10)
	table.insert(arr,q)
	table.insert(arr,b)
	table.insert(arr,s)
	table.insert(arr,g)
	if(isSame(arr) == false)then
		arr = {}
		table.insert(arr,sw)
		table.insert(arr,w)
		table.insert(arr,qq)
		table.insert(arr,bb)
		table.insert(arr,ss)
		table.insert(arr,gg)
		if(isSame(arr) == false)then
			print("a=",a,"c=",c,"d=",d)
			GetXYByA(a)
		end
	end
end




原文地址:https://www.cnblogs.com/byfei/p/6389726.html