杭电2161.。 http://acm.hdu.edu.cn/showproblem.php?pid=2161
#include<iostream>#include<cmath>usingnamespacestd;intmain(){intn,i,a=1;while(cin>>n)...
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i,a=1;
while(cin>>n)
{ if(n<=0)break;
cout<<a<<": ";
if(n==1||n==2)
cout<<"no"<<endl;
else
{
for(i=2;i<=sqrt(n);i++)
if(n%i==0) break;
if(i>sqrt(n))
{
cout<<"yes"<<endl;
}
else
{
cout<<"no"<<endl;
}
}
a++;
}
return 0;
}
大侠来,,看一看,帮帮忙,,啊 。。
http://acm.hdu.edu.cn/showproblem.php?pid=2161 展开
#include<cmath>
using namespace std;
int main()
{
int n,i,a=1;
while(cin>>n)
{ if(n<=0)break;
cout<<a<<": ";
if(n==1||n==2)
cout<<"no"<<endl;
else
{
for(i=2;i<=sqrt(n);i++)
if(n%i==0) break;
if(i>sqrt(n))
{
cout<<"yes"<<endl;
}
else
{
cout<<"no"<<endl;
}
}
a++;
}
return 0;
}
大侠来,,看一看,帮帮忙,,啊 。。
http://acm.hdu.edu.cn/showproblem.php?pid=2161 展开
展开全部
//改成这样AC了
#include<iostream>
using namespace std;
int main()
{
int n,i,a=1;
while(cin>>n)
{ if(n<=0)break;
cout<<a<<": ";
if(n==1||n==2)
cout<<"no"<<endl;
else
{
for(i=2;i*i<=n;i++)////////////
if(n%i==0) break;
if(i*i>n)///////////////////////
{
cout<<"yes"<<endl;
}
else
{
cout<<"no"<<endl;
}
}
a++;
}
return 0;
}
或
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i,a=1;
while(cin>>n)
{ if(n<=0)break;
cout<<a<<": ";
if(n==1||n==2)
cout<<"no"<<endl;
else
{
for(i=2;i<=sqrt((double)n);i++)//////////////
if(n%i==0) break;
if(i>sqrt((double)n))///////////////////
{
cout<<"yes"<<endl;
}
else
{
cout<<"no"<<endl;
}
}
a++;
}
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int n,i,a=1;
while(cin>>n)
{ if(n<=0)break;
cout<<a<<": ";
if(n==1||n==2)
cout<<"no"<<endl;
else
{
for(i=2;i*i<=n;i++)////////////
if(n%i==0) break;
if(i*i>n)///////////////////////
{
cout<<"yes"<<endl;
}
else
{
cout<<"no"<<endl;
}
}
a++;
}
return 0;
}
或
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i,a=1;
while(cin>>n)
{ if(n<=0)break;
cout<<a<<": ";
if(n==1||n==2)
cout<<"no"<<endl;
else
{
for(i=2;i<=sqrt((double)n);i++)//////////////
if(n%i==0) break;
if(i>sqrt((double)n))///////////////////
{
cout<<"yes"<<endl;
}
else
{
cout<<"no"<<endl;
}
}
a++;
}
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询