java - 数的质因数

标签 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 开始,每次将 i 递增 1 检查 f(x)。有什么有效的方法吗?
    1. 我也在继续循环,直到我得到答案。是否可以使用其他一些结束条件来完成,因为它可能会进入无限循环? 请帮忙

最佳答案

每个数字都可以表示为:

x = a1p1.a1p1...anpn

地点:

ai 1 <= i <= n 是质因数。

因此,要使 x 尽可能小,所有因子都应为 2,因此 x 将为 2 ^ f( x).

x 的约数是:(p1 + 1)(p2 + 1)...(pn + 1) 所以你添加的条件也将得到满足!

关于java - 数的质因数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40068202/

相关文章:

algorithm - 面试题: Buy and sell stocks to maximize profit with constraint of not buying once you sell

java - 使用对象或整数作为 HashMap 键更好吗?

java - 当方法是静态时如何将计算值添加到字符串

为每个英文单词生成唯一序列号的算法

c# - 获取所有项目组合

algorithm - 将数组分成两部分的实现,使两部分的平均值相等

java - 如何使用 Java Webapp 将文件上传到 MongoDB?

java - 不可变类字段查询

java - 从 m 个集合中获取 n 个元素的所有不同组合

algorithm - 对象堆叠,动态规划