码迷,mamicode.com
首页 > 其他好文 > 详细

1561 PRIME

时间:2016-10-22 15:06:55      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:space   i++   ios   ace   names   while   prime   cout   mat   

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
   int n;
   cin>>n;
   if(n==1) {
     cout<<2<<endl;
     return 0;
   }
   n=n-1;
   int t=3;
   while(t<=104730){
       bool flag=true;
       for( int i=2;i<=sqrt(t);i++){
          if(t%i==0) flag = false;
          continue;
       }
       if(flag==true) {
           n--;
           if(n==0){
               cout<<t<<endl;
               return 0;
           }
       }
       t=t+2;
   }

}

1561 PRIME

标签:space   i++   ios   ace   names   while   prime   cout   mat   

原文地址:http://www.cnblogs.com/sysu-eeman-yang/p/5987459.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!