Epic - Seed Number

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
上一篇:ASP.Net Core使用分布式缓存Redis从入门到实战演练


下一篇:笔记:程序内存管理 .bss .data .rodata .text stack heap