c#孪生素数查找程序_C ++程序查找最大的质数列表
c#孪生素数查找程序
Problem statement:
问题陈述:
You are given a number N, you have to find the largest list of prime numbers that will give N after summation of the list.
给您一个数字N ,您必须找到最大的质数列表,该列表加总后将得出N。
Example:
例:
Sample Input:72Sample Output:2 2 32
Explanation:
说明:
7 can be expressed as summation of 2+2+32 can be expressed as summation of 2
Basic Idea:
基本思路:
A number can be expressed as summation of longest list of prime numbers only when it is expressed only with 2 and 3.
仅当数字仅用2和3表示时,才可以将其表示为最长质数列表的总和。
Algorithm:
算法:
prime_List(N)1. if(N%2)==02. Express it as summation of (N/2) number of 23. Else if(N%2)!=0//So that N can be even, for example N=19, so now N=19-3=164. Set N=N-3 5. Print (N/2) numbers of 26. Print 37. END of Program.
C++ program
C ++程序
#include
using namespace std;int list_prime(int n)
{ int i;if(n<2){cout<<"Summation not possible\n";}//if n can be divided by 2, then we can express //it as summation of 2 onlyelse if(n%2==0) {for(i=1;i<=n/2;i++){cout<<2<<" ";}}else{//making the number evenn=n-3;//n can be divided by 2 nowfor(i=1;i<=n/2;i++) cout<<2<<" ";//add 3, and the summation will be now ncout<<3<<" ";}
}int main()
{int i,n;cin>>n;list_prime(n);return 0;
}
Output
输出量
7
2 2 3
翻译自: https://www.includehelp.com/cpp-programs/find-largest-list-of-prime-numbers.aspx
c#孪生素数查找程序
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
