青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

C++研究

C++細節深度探索及軟件工程

  C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
  37 隨筆 :: 0 文章 :: 74 評論 :: 0 Trackbacks


1.GRIDDLE METHOD (ALSO CALLED SIFT METHOD)

When I was a student in Bachelor phrase , a teacher has tought me a method called griddle method , it's principle is:

if a number can be devided by another number(except 1) , it isn't a prime , so , we set the non-prime at zero. after all number [In fact , half of the range checked is OK ]test finished , We simply output the NON-ZERO number , it 's the prime table in the RANGE.

E.G
Define the Range from 1-100;

/********************************************************************
 created: 2007/04/19
 created: 19:4:2007   3:00
 filename:  C:\testvc6\TestStll\TestStll.cpp
 file path: C:\testvc6\TestStll
 file base: TestStll
 file ext: cpp
 author:  Chang xinglong(King.C)
 purpose: Print Prime Table in RANGE(1-100)
*********************************************************************/

The Code Here :

 


#include 
<iostream>
#include 
<algorithm>
#include 
<vector>
using namespace std;

void InitArray(int A[] ,int len)
{
    
for (int i=0;i<len;i++)
    
{
        A[i]
=i+1;
    }

}


void OutputPrime(int A[] ,int len)
{
  
for (int i=2;i<len;i++)
  
{
      
for (int j=2;i*j<=len;j++)
      
{
          A[i
*j-1]=0;
          cout
<<i<<","<<j<<","<<i*j<<endl;
      }

     
  }

  
for (i=0;i<len;i++)
  
{
      
if (A[i]!=0)
      
{
          cout
<<A[i]<<" ";
      }

      
  }

  cout
<<endl;
}

// Main Method [4/19/2007 Changxinglong (King.C)]
int main(int argc, char* argv[])
{
    
int A[100];
    InitArray(A,
100);
    OutputPrime(A,
100);
    
return 1;
}




 2.THE DIRECT METHOD

E.G

/********************************************************************
 created: 2007/04/19
 created: 19:4:2007   3:00
 filename:  C:\testvc6\TestStll\TestStll.cpp
 file path: C:\testvc6\TestStll
 file base: TestStll
 file ext: cpp
 author:  Chang xinglong(King.C)
 purpose: Prime ?
*********************************************************************/

Here is the Kernel Function(Quote : STL TURORIAL REFERRENCE):

 

 1//predicate, which returns whether an integer is a prime number
 2bool isPrime (int number)
 3{
 4//ignore negative sign
 5number = abs(number);
 6// 0 and 1 are prime numbers
 7if (number == 0 || number == 1{
 8return true;
 9}

10//find divisor that divides without a remainder
11int divisor;
12for (divisor = number/2; number%divisor != 0--divisor) {
13;
14}

15//if no divisor greater than 1 is found, it is a prime number
16return divisor == 1;
17}


In Main Function , traverse the given range judge every number use the above function:

int main(int argc , char * argv[])
{
  
int A[100];
  InitArray(A,
100);
  
for(int i=0;i<100;i++)
    
if(isPrime(A[i]))
       cout
<<A[i]<<endl;
}

3. Extention
 Further , if  there is a given List or Vector and it's filled with data , how can you find the prime number in the data effiectly ?
STL Algorithm can help you indeed. After the step two , we can write a few code to implement the function:
int main()
{
list
<int> coll;
//insert elements from 1 to 100
for (int i=1; i<=100++i) {
coll.push_back(i);
}

//search for prime number
list<int>::iterator pos;
pos 
= find_if (coll.begin(), coll.end(), //range
isPrime); //predicate
if (pos != coll.end()) {
//found
cout << *pos << " is first prime number found" << endl;
}

else {
//not found
cout << "no prime number found" << endl;
}

}


posted on 2007-04-19 03:05 常興龍 閱讀(1360) 評論(8)  編輯 收藏 引用 所屬分類: Algorithm

評論

# re: Some algorithms about judging a prime . 2007-04-19 10:58 uglystone
Write well!
I think tha IsPrime funtion shoule be implemented as a functors!
it may be more elegant!
class IsPrime{
public:
IsPrime(){
}
bool isPrime (int number)
{
.....
}
};  回復  更多評論
  

# re: Some algorithms about judging a prime . 2007-04-19 22:18 chenger
這應該是最原始的辦法  回復  更多評論
  

# re: Some algorithms about judging a prime . 2007-04-26 19:00 oyjpart
有一些很好的隨機算法  回復  更多評論
  

# re: Some algorithms about judging a prime . 2007-05-12 23:26 不是很懂
A primality test is a test to determine whether or not a given number is prime, as opposed to actually decomposing the number into its constituent prime factors (which is known as prime factorization).

Primality tests come in two varieties: deterministic and probabilistic. Deterministic tests determine with absolute certainty whether a number is prime. Examples of deterministic tests include the Lucas-Lehmer test and elliptic curve primality proving. Probabilistic tests can potentially (although with very small probability) falsely identify a composite number as prime (although not vice versa). However, they are in general much faster than deterministic tests. Numbers that have passed a probabilistic prime test are therefore properly referred to as probable primes until their primality can be demonstrated deterministically.

A number that passes a probabilistic test but is in fact composite is known as a pseudoprime. There are many specific types of pseudoprimes, the most common being the Fermat pseudoprimes, which are composites that nonetheless satisfy Fermat's little theorem.

The Rabin-Miller strong pseudoprime test is a particularly efficient test. Mathematica versions 2.2 and later have implemented the multiple Rabin-Miller test in bases 2 and 3 combined with a Lucas pseudoprime test as the primality test used by the function PrimeQ[n]. Like many such algorithms, it is a probabilistic test using pseudoprimes. In order to guarantee primality, a much slower deterministic algorithm must be used. However, no numbers are actually known that pass advanced probabilistic tests (such as Rabin-Miller) yet are actually composite.

The state of the art in deterministic primality testing for arbitrary numbers is elliptic curve primality proving. As of 2004, the program PRIMO can certify a 4769-digit prime in approximately 2000 hours of computation (or nearly three months of uninterrupted computation) on a 1 GHz processor using this technique.

Unlike prime factorization, primality testing was long believed to be a P-problem (Wagon 1991). This had not been demonstrated, however, until Agrawal et al. (2002) unexpectedly discovered a polynomial time algorithm for primality testing that has asymptotic complexity of (Bernstein 2002, Clark 2002, Indian Institute of Technology 2002, Pomerance 2002ab, Robinson 2002). Their algorithm has come to be called the AKS primality test.

http://mathworld.wolfram.com/PrimalityTest.html  回復  更多評論
  

# re: Some algorithms about judging a prime . 2007-05-17 00:12 天津大學計算機學院 常興龍
Very appreciated for your comment , I have benefited a lot from it. thanks again!  回復  更多評論
  

# re: Some algorithms about judging a prime . 2008-04-24 02:01 Rex.Kingsir
Thanks a lot for talk so much!  回復  更多評論
  

# re: Some algorithms about judging a prime . 2008-07-05 16:45 我們一起來提高
數論學家利用費馬小定理研究出了多種素數測試方法,目前最快的算法是拉賓米
勒測試算法,其過程如下:
(1)計算奇數M,使得N=(2**r)*M+1
(2)選擇隨機數A<N
(3)對于任意i<r,若A**((2**i)*M) MOD N = N-1,則N通過隨機數A的測試
(4)或者,若A**M MOD N = 1,則N通過隨機數A的測試
(5)讓A取不同的值對N進行5次測試,若全部通過則判定N為素數
若N 通過一次測試,則N 不是素數的概率為 25%,若N 通過t 次測試,則N 不是
素數的概率為1/4**t。事實上取t 為5 時,N 不是素數的概率為 1/128,N 為素數的
概率已經大于99.99%。
在實際應用中,可首先用300—500個小素數對N 進行測試,以提高拉賓米勒測試
通過的概率,從而提高測試速度。而在生成隨機素數時,選取的隨機數最好讓 r=0,
則可省去步驟(3) 的測試,進一步提高測試速度
  回復  更多評論
  

# re: Some algorithms about judging a prime . 2009-05-16 19:29 u2u
@我們一起來提高
現在最快的是AKS...  回復  更多評論
  

> hi的博客
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美影视一区| 欧美电影打屁股sp| 美女主播一区| 美女精品网站| 欧美激情久久久久| 亚洲欧洲一区二区在线播放| 欧美国产视频在线| 亚洲三级免费| 亚洲中字黄色| 久久艳片www.17c.com| 欧美mv日韩mv国产网站| 欧美日本精品| 国产婷婷精品| 亚洲精品国久久99热| 亚洲一区二区少妇| 久久久欧美精品| 99riav1国产精品视频| 欧美一区二区女人| 欧美丰满高潮xxxx喷水动漫| 国产精品久久久一区麻豆最新章节| 国产日韩欧美三级| 亚洲欧洲美洲综合色网| 欧美一级电影久久| 亚洲国产乱码最新视频| 亚洲一区二区三区视频播放| 久久夜色精品国产欧美乱| 欧美系列一区| 亚洲精品美女在线观看播放| 99这里只有精品| 在线日韩成人| 亚洲综合精品四区| 欧美/亚洲一区| 亚洲欧美春色| 欧美三区在线观看| 亚洲黄网站在线观看| 久久高清免费观看| 欧美日韩精品一区| 久热国产精品视频| 欧美精选一区| 在线观看成人一级片| 亚洲综合久久久久| 亚洲人成精品久久久久| 久久久久五月天| 国产精品永久免费| 亚洲一区二区三区在线播放| 亚洲国产精品va在线观看黑人| 欧美一区二区三区免费观看视频| 欧美日韩在线一区二区| 亚洲福利视频三区| 美女主播一区| 久久久久久综合| 黄色成人av在线| 久久久成人网| 欧美在线看片| 国产一区二区三区免费观看| 午夜久久99| 亚洲免费中文字幕| 国产日韩精品一区二区三区在线| 亚洲女人av| 国产精品二区在线观看| 午夜精品99久久免费| 国产精品久久久久久久7电影| 夜夜嗨网站十八久久| 亚洲人午夜精品免费| 欧美韩国日本一区| 日韩亚洲欧美成人| 99国产精品| 欧美午夜在线视频| 午夜在线一区二区| 欧美一区永久视频免费观看| 国产永久精品大片wwwapp| 久久精品国产99精品国产亚洲性色| 亚洲在线视频一区| 国内成人精品一区| 蜜桃精品久久久久久久免费影院| 久久久精品性| 亚洲精品欧美日韩| 一区二区三欧美| 国产麻豆日韩欧美久久| 久久亚洲国产精品一区二区| 久久综合九色综合欧美狠狠| 夜夜嗨av一区二区三区中文字幕| 亚洲作爱视频| 国产一区欧美| 亚洲黑丝在线| 国产精品夜夜嗨| 女人香蕉久久**毛片精品| 欧美ed2k| 亚洲欧洲av一区二区| 欧美在线观看一区| 亚洲精品亚洲人成人网| 亚洲一区久久| 亚洲国产精品ⅴa在线观看 | 亚洲国产精品va在线看黑人| 蜜臀a∨国产成人精品| 午夜精品福利在线观看| 久久精品日产第一区二区三区| 国产日韩在线看片| 亚洲国产欧美日韩另类综合| 欧美日韩少妇| 久久亚洲综合网| 欧美日韩在线视频一区二区| 久久久亚洲国产美女国产盗摄| 欧美第一黄网免费网站| 久久激情久久| 欧美日韩国产不卡| 美玉足脚交一区二区三区图片| 欧美日韩免费| 欧美韩日一区二区| 国产欧美一区二区精品婷婷| 亚洲国产欧美国产综合一区 | 国产精品成人在线| 模特精品裸拍一区| 国产麻豆精品视频| 夜夜爽99久久国产综合精品女不卡| 国语自产在线不卡| 亚洲欧美国产另类| 亚洲一区二区免费| 欧美国产综合| 亚洲区中文字幕| 亚洲国产小视频在线观看| 久久精品成人一区二区三区| 亚洲综合电影| 欧美日韩亚洲激情| 亚洲黄色免费电影| 亚洲黄一区二区三区| 久久久综合网| 国产欧美一区二区精品秋霞影院| 亚洲欧洲日韩综合二区| 国产一区在线免费观看| 这里只有精品在线播放| 亚洲美女性视频| 欧美高清视频在线播放| 亚洲成色999久久网站| 伊人色综合久久天天五月婷| 久久精精品视频| 久久黄色级2电影| 国产亚洲精品一区二区| 午夜免费电影一区在线观看| 欧美一区=区| 国产婷婷精品| 久久久欧美精品| 欧美国产视频在线观看| 亚洲精品一区二| 欧美另类99xxxxx| 夜夜狂射影院欧美极品| 亚洲女ⅴideoshd黑人| 国产欧美日韩一区二区三区| 亚洲影视中文字幕| 久久精品国产久精国产思思| 国产日韩视频| 久久色在线播放| 亚洲全部视频| 午夜视频在线观看一区二区三区| 国产精品自在线| 久久蜜臀精品av| 亚洲欧洲一区二区天堂久久 | 久久疯狂做爰流白浆xx| 国语自产精品视频在线看8查询8| 久久一日本道色综合久久| 久久一区二区三区四区| 欧美在线视频不卡| 欧美日本一区| 亚洲小少妇裸体bbw| 久久久久久久久岛国免费| 亚洲黄色免费| 国产精品高潮呻吟久久av黑人| 西瓜成人精品人成网站| 欧美激情麻豆| 香蕉视频成人在线观看| 亚洲第一精品福利| 欧美色偷偷大香| 久久精品72免费观看| 日韩视频在线永久播放| 久久久久国色av免费看影院 | 亚洲视频在线观看视频| 久久久国产亚洲精品| 亚洲破处大片| 国产精品青草久久| 麻豆精品在线视频| 亚洲在线视频观看| 亚洲国产另类精品专区 | 最新亚洲激情| 久久久www成人免费毛片麻豆| 亚洲人成在线观看一区二区| 国产精品乱码一区二区三区| 狂野欧美性猛交xxxx巴西| 亚洲一二三区在线观看| 亚洲精品123区| 免费久久精品视频| 久久爱91午夜羞羞| 亚洲一区二区三区成人在线视频精品| 国产综合自拍| 国产欧美日韩不卡免费| 欧美视频不卡| 欧美国产精品中文字幕| 久久九九久精品国产免费直播| 午夜一区不卡| 久久精品成人一区二区三区蜜臀| 亚洲视频欧美视频|