Epic - Seed Number

时间:2022-09-27 19:48:18

Find the seed of a number.

Eg : 1716 = 143*1*4*3 =1716 so 143 is the seed of 1716. find all possible seed for a given number.

辗转相除法,由性质可利用 sqrt(num) <= seed_number <= num/2 缩小范围。

def seed_number(num)
seed = Math.sqrt(num).to_i
while seed <= num / 2
if num % seed == 0
product = temp = seed
while temp != 0
product *= temp%10
temp /= 10
end
return seed if product == num
end
seed += 1
end
end