简体   繁体   English

对于给定的数字N,我必须找到它所组成的所有素数

[英]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.

相关问题 给定一个由N个数字组成的数组,求出所有长度为R?的序列的数目。 - Given an array of N numbers,find the number of sequences of all lengths having the range of R? N下所有素数的优化求和 - Optimized Summation of all prime numbers under N 给定一个仅包含 1 和 0 的 N × M 矩阵,找到仅包含 1 的最大矩形并返回其面积 - Given an N by M matrix consisting only of 1's and 0's, find the largest rectangle containing only 1's and return its area 给定数字 n 找到它之前的偶数正数的总和 - Given number n find the sum of the even positive numbers before it 如何找到所有匹配的数字,在给定的数组中总和为'N' - How to find all matching numbers, that sums to 'N' in a given array 尝试使用C ++中的Eratosthenes筛子查找2至n的所有质数时出错 - Error trying to find all the prime numbers from 2 to n using Sieve of Eratosthenes in C++ 如何找到可以除以所有数字 1:n 且没有余数的最小数字? - How do I find the smallest number than can be divided by all numbers 1:n with no remainder? 我必须找到给定数组中所有数字的周期,就像有很多解决方案但数组的大小是 10^5 - I have to find the period of all numbers in an given array, like there are many solutions but size of the array is 10^5 试图在列表中找到所有素数 - Trying to find all prime numbers in a list 打印给定数字范围内的素数。 我无法使代码工作 - Print prime numbers from a given number range. I cannot make the code work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM