The first primes
問題描述
輸出10000以內的素數。
輸入
無。
輸出
按從大到小的順序輸出10000以內的素數,每個數占一行。
樣例輸出
9973
9967
9949
9941
9931
…
… (其他素數)
…
7
5
3
2
#include <iostream>
#include <cmath>
using namespace std;
bool pri(int n)


{
for (int i=2; i<=sqrt(double(n)); i++)
if (n%i==0) return false;
return true;
}

int main()
{
for (int i=9997; i>=2; i--)
if ( pri(i) )
cout<<i<<endl;
return 0;
}
posted on 2009-12-27 08:37
jyy 閱讀(74)
評論(0) 編輯 收藏 引用 所屬分類:
OJ平臺