| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 501 人关注过本帖
标题:一道很简单的ACM 判断素数题,请各位前辈帮忙看看,感谢~!!!
只看楼主 加入收藏
dreamjack
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-10-23
收藏
 问题点数:0 回复次数:0 
一道很简单的ACM 判断素数题,请各位前辈帮忙看看,感谢~!!!
Problem description
Given a big integer number, you are required to find out whether it's a prime number.

Input
The first line contains the number of test cases T (1 <= T <= 20 ), then the following T lines each contains an integer number N (2 <= N < 254).

Output
For each test case, if N is a prime number, output a line containing the word "Prime", otherwise, output a line containing the smallest prime factor of N.

Sample Input
2
5
10
Sample Output
Prime
2

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
     int T;
     long i,k,N;
     bool p;
     cin>>T;
     while(T--)
     {
         cin>>N;
         if(N==1) cout<<N<<endl;
         else
         {
         p=true;
         k=long(sqrt(N));
         for(i=2;i<=k;i++)
           if(N%i==0)
           {
               cout<<i<<endl;
               p=false;
               break;
           }
         if(p)
             cout<<"prime"<<endl;
         }     
     }
     return 0;
}

上面是小弟的程序,一提交就 Wrong Answer,咋回事啊 请各位前辈指教,O(∩_∩)O谢谢啦~!!!
搜索更多相关主题的帖子: 素数 ACM 前辈 判断 
2010-10-23 19:43
快速回复:一道很简单的ACM 判断素数题,请各位前辈帮忙看看,感谢~!!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016077 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved