[英]For a given number N i have to find all the prime numbers it's consisting of
Need a suggestion for an algorithm. 需要有关算法的建议。
For a given number N i have to find all the prime numbers it's consisting of, like this: 对于给定的数字N,我必须找到其组成的所有质数,如下所示:
N = 49
49 = 7 ^ 2
N = 168
168 = (2 ^ 3) * (3 ^ 1) * (7 ^ 1)
If you want to help me even more you can write the algo in c++. 如果您想进一步帮助我,可以使用C ++编写算法。
Thanks. 谢谢。
The most straightforward way is trial division. 最直接的方法是审判分庭。 Basically just try dividing n by each prime number up to sqrt(n).
基本上,只需尝试将n除以每个质数,直到sqrt(n)。 For large numbers, this is a very slow algorithm.
对于大数,这是一个非常慢的算法。
http://en.wikipedia.org/wiki/Trial_division http://en.wikipedia.org/wiki/Trial_division
For more sophisticated algorithms, try http://en.wikipedia.org/wiki/Integer_factorization 有关更复杂的算法,请尝试http://en.wikipedia.org/wiki/Integer_factorization
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.