数字的主要因素

时间:2016-10-16 08:01:51

标签: java algorithm dynamic-programming

这是问题

f(x)=sum of power of prime factor of x
now if f(x) is given then find the least value of x which also setisfy the condition
(No of divisor of x)-1=f(x).
Eg: f(x)=2 given and i need to find x 
Step 1:check for x=2 then f(x)=1
Step 2:check for x=3 then f(x)=1
Step 3: check for x=4 then f(x)=2 (i.e-x=2^2,and we know that f(x) is some of power of prime factor so f(x) here is 2)
And divisor of 4 is 1,2 & 4 so ,no of divisor -1=f(x)

so the Answer is x=4.

Now the approach i followed
Step 1-start for i=2 till we get the answer
step 2-find the prime factor for i and calculate the sum of power
Step 3-check if calculated sum is equal to the f(x) or not if not then increment i and repeat from step -1.

现在我的问题是

  1. 我从i = 2开始,每次以1为增量i检查f(x)。有没有有效的方法呢?
    1. 我也在继续循环直到得到答案。可以用其他一些结束条件来完成,因为它可能会进入无限循环吗? 请帮助

1 个答案:

答案 0 :(得分:4)

每个数字都可以表示为:

x = a 1 p 1 .a 1 p 1 ...一个<子>名词 p <子>名词

其中:

a i 1&lt; = i&lt; = n是主要因素。

因此,x最小可能所有因素都应为2,因此x将为2 ^ f(x)

x的除数是:(p 1 + 1)(p 2 + 1)...(p n < / sub> + 1)所以你的附加条件也会得到满足!