Java 素数

Java 素数,java,algorithm,dynamic-programming,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

问题是

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.
现在我的问题是

  • 我从I=2开始,每次以1的增量I检查f(x)。有什么有效的方法可以做到这一点吗?
  • 我还在继续循环,直到得到答案。因为它可能在无限循环中运行,所以它可以用其他的终端条件来完成吗? 请帮忙

  • 每个数字都可以用以下形式表示:

    x=a1p1.a1p1…anpn

    其中:


    ai 1如果f(x)=y,最小解不是总是2^y吗?@Henry sry我错过了这里现在添加的另一个条件。感谢你的加入,第二个条件不会改变任何东西,因为2^y有y+1个除数。我真的很抱歉我错过了那里的一个条件(x的除数的数目)-1=f(x)。现在我补充说。谢谢这位男士的参与。
    快乐编码
    :)
    我同意,但我不明白你是怎么发现op在问这个问题的…@Xentros,是的,这个问题一开始看起来有点神秘<代码>:)