C++中的排列组合

2024-11-28 23:43:31
推荐回答(1个)
回答(1):

#include做搜纳
#include
const int N=21;
using namespace std;
int issushu(long num)
{
for(long i=2;i<=sqrt(num);i++)
if(num%i==0)
return 0;
return 1;
}
long totalsum(long a[],int n)
{
long sum=0;
for(int i=0;i sum+=a[i];
return sum;
}
int main()
{
cout<
choose numbers:";
int num=0,k=0;
cin>>num>>漏没k;
cout<<"please input "<纯没 long num1[N],num2[N];
for(int i=0;i cin>>num1[i];
long num3=0,count=0;
for(int j=0;j num2[j]=num1[j];
num3=totalsum(num2,k);
if(issushu(num3))
count++;
int m=0;
long data=0;
for(int n=0;n {
data=num2[n];
for(m=k;m {
num2[n]=num1[m];
num3=totalsum(num2,k);
if(issushu(num3))
count++;
}
num2[n]=data;
}
cout< return 0;
}