Acm练习(七)
1.素数求和
#include<iostream>
using namespace std;
int sushu(int x)
{
int i=2;
if(x==1) return 0;
for(;i<=x/2;i++)
{
if(x%i==0)
return 0;
}
return x;
}
int main()
{
int sum=0;
int kk;
cin>>kk;
for(int g=0;g<kk;g++)
{
int kk1;
cin>>kk1;
for(int l=0;l<kk1;l++)
{
int kk2;
cin>>kk2;
sushu(kk2);
sum=sum+sushu(kk2);
}
cout<<sum<<endl;
sum=0;
}
return 0;
}
2鸡兔同笼
#include<iostream>
using namespace std;
void jitu(int n,int m)
{
if(4*n-m<0)
{
cout<<"No answer"<<endl;
}
else
{
if((4*n-m)%2!=0||(4*n-m)/2>n||(4*n-m)/2<0)
{
cout<<"No answer"<<endl;
}
else
{
cout<<(4*n-m)/2<<" "<<n-(4*n-m)/2<<endl;
}
}
}
int main()
{
int N;
cin>>N;
for(int i=0;i<N;i++)
{
int x,y;
cin>>x>>y;
jitu(x,y);
}
return 0;
}