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

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 常興龍 閱讀(1379) 評論(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>
            午夜天堂精品久久久久| 欧美在线精品免播放器视频| 免费av成人在线| 在线视频国内自拍亚洲视频| 麻豆精品精品国产自在97香蕉| 久久av资源网站| 亚洲国产成人porn| 亚洲欧洲一区二区三区| 欧美日韩成人一区| 午夜精品三级视频福利| 欧美一区二区三区久久精品| 激情久久中文字幕| 91久久精品国产91久久性色tv| 欧美日韩国产美| 羞羞答答国产精品www一本| 久久精品盗摄| 99ri日韩精品视频| 亚洲免费在线电影| 亚洲风情亚aⅴ在线发布| 亚洲精品国产精品乱码不99| 国产精品嫩草久久久久| 免费在线欧美黄色| 国产精品videossex久久发布| 久久成人18免费观看| 欧美成人网在线| 欧美一区二区三区精品| 麻豆免费精品视频| 欧美亚洲免费电影| 欧美大片一区| 久久精品一区四区| 欧美理论电影网| 久久亚洲精品一区| 欧美无乱码久久久免费午夜一区| 久久九九久精品国产免费直播| 欧美高清视频www夜色资源网| 欧美一区成人| 欧美日韩国产麻豆| 欧美电影在线观看| 国产精品无码永久免费888| 欧美成人精品福利| 国产欧美日韩在线| 日韩视频专区| 亚洲啪啪91| 久久精品91久久久久久再现| 亚洲欧美国产精品桃花| 欧美国产精品劲爆| 免费中文字幕日韩欧美| 国产精品嫩草久久久久| 亚洲美女av网站| 亚洲激情另类| 久久性色av| 久久婷婷av| 国产日本欧美一区二区三区在线| 日韩小视频在线观看专区| 亚洲激情中文1区| 久久久久99| 久久久噜噜噜久久中文字幕色伊伊| 欧美网站大全在线观看| 亚洲精品久久在线| 日韩天堂在线视频| 欧美岛国激情| 亚洲国产欧美日韩精品| 亚洲国产精品视频一区| 麻豆精品传媒视频| 欧美承认网站| 亚洲精品免费观看| 欧美高清视频一区二区| 亚洲电影第1页| 一区二区毛片| 一本色道久久综合狠狠躁篇的优点 | 亚洲欧美日韩电影| 欧美精品激情blacked18| 亚洲国产精品va| 99国产精品久久久| 欧美日韩亚洲一区二区三区在线| 免费中文字幕日韩欧美| 亚洲区中文字幕| 欧美区一区二| 宅男精品视频| 久久久福利视频| 亚洲国产视频一区| 欧美日韩在线免费观看| 亚洲天堂成人在线视频| 久久久99久久精品女同性| 在线观看三级视频欧美| 欧美国产日本| 亚洲小说欧美另类婷婷| 久久久久一区二区| 亚洲精品乱码久久久久久| 欧美日韩久久| 午夜久久久久| 亚洲第一区在线| 亚洲欧美精品在线| 精品不卡一区二区三区| 欧美激情综合色| 午夜久久资源| 亚洲国产精品成人| 小黄鸭精品密入口导航| 亚洲高清网站| 欧美三区在线| 久久香蕉精品| 亚洲一区久久久| 亚洲承认在线| 狠久久av成人天堂| 欧美久久视频| 久久精品视频网| 夜夜爽www精品| 蜜桃av一区| 午夜精品成人在线| 亚洲国产一二三| 国产日韩欧美综合精品| 欧美精品日韩www.p站| 午夜视频在线观看一区二区| 最近中文字幕日韩精品| 久久精品视频一| 亚洲一区二区精品视频| 亚洲激情不卡| 国内久久婷婷综合| 国产精品乱码一区二三区小蝌蚪| 美女黄毛**国产精品啪啪 | 欧美在线观看网站| 99精品国产在热久久婷婷| 禁久久精品乱码| 国产欧美日韩另类一区 | 午夜亚洲视频| 一区二区三区国产盗摄| 亚洲第一在线视频| 免费成人黄色av| 久久精品国产v日韩v亚洲 | 亚洲第一天堂无码专区| 国产乱子伦一区二区三区国色天香 | 免费在线欧美视频| 性欧美1819性猛交| 夜夜嗨av色一区二区不卡| 欧美激情麻豆| 免费短视频成人日韩| 久久久精品日韩| 欧美在线视频免费观看| 亚洲永久免费| 亚洲欧美bt| 午夜精品久久久久久久99水蜜桃| 亚洲视频电影图片偷拍一区| 日韩一级网站| 中文在线一区| 亚洲丝袜av一区| 亚洲一区日韩在线| 午夜免费久久久久| 性做久久久久久久久| 久久爱www.| 久久久久欧美| 欧美wwwwww| 亚洲国产免费| 一二美女精品欧洲| 亚洲免费伊人电影在线观看av| 亚洲五月六月| 久久成人免费| 欧美高清在线观看| 欧美日韩亚洲国产一区| 欧美系列电影免费观看| 国产区在线观看成人精品| 国产一区二区高清| 亚洲国内高清视频| 亚洲视频精选| 欧美一区二区三区视频免费播放| 久久精品道一区二区三区| 久久在线视频| 亚洲精品在线免费观看视频| 亚洲香蕉成视频在线观看| 欧美一区二区三区在| 蜜桃久久精品乱码一区二区| 欧美精品在线一区| 国产精品亚洲综合| 在线免费观看日本一区| 在线亚洲美日韩| 久久精品官网| 91久久精品美女| 亚洲欧美在线网| 欧美福利一区| 国产亚洲欧美一区| 亚洲美女在线看| 欧美一区二区大片| 欧美激情一区二区三区不卡| 一本色道久久综合| 久久久久久电影| 国产精品大片免费观看| 亚洲成人自拍视频| 亚洲综合成人在线| 欧美大片在线观看一区| 在线综合亚洲| 欧美激情亚洲精品| 国产伊人精品| 亚洲欧美综合国产精品一区| 亚洲盗摄视频| 欧美一区二区在线观看| 欧美日韩亚洲另类| 亚洲国产裸拍裸体视频在线观看乱了中文 | 亚洲视频1区2区| 猫咪成人在线观看| 国产精品蜜臀在线观看| 亚洲精品一区在线|