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

C++研究

C++細節(jié)深度探索及軟件工程

  C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
  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 常興龍 閱讀(1375) 評論(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)
{
.....
}
};  回復(fù)  更多評論
  

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

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

# 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  回復(fù)  更多評論
  

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

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

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

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

> 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>
            亚洲欧美国产va在线影院| 亚洲视频导航| 美女黄网久久| 久久九九精品| 亚洲电影在线播放| 欧美高清hd18日本| 欧美成人免费网站| 亚洲免费人成在线视频观看| 宅男精品视频| 国产在线观看精品一区二区三区| 久久久久久久久久久成人| 久久久久女教师免费一区| 精品成人一区二区三区四区| 快播亚洲色图| 欧美精品免费在线观看| 亚洲欧美日韩国产成人精品影院| 亚洲欧美日韩国产另类专区| 国产在线精品自拍| 亚洲国产第一| 国产精品va在线播放我和闺蜜| 羞羞漫画18久久大片| 久久久99免费视频| 一二美女精品欧洲| 欧美一区精品| 日韩亚洲欧美一区二区三区| 午夜精品区一区二区三| 亚洲欧洲日韩女同| 亚洲男人影院| 亚洲欧洲日韩在线| 亚洲欧美日韩爽爽影院| 亚洲人成77777在线观看网| 亚洲午夜精品久久久久久app| 国产一区二区三区在线观看免费| 亚洲高清资源| 国产亚洲欧美日韩美女| 亚洲精品日韩在线观看| 国产亚洲a∨片在线观看| 亚洲国产精品视频| 国产一区二区看久久| 亚洲乱码国产乱码精品精可以看 | 久久综合久久综合久久| 欧美人与禽猛交乱配| 久久综合色一综合色88| 欧美午夜不卡影院在线观看完整版免费 | 久久全球大尺度高清视频| 在线视频亚洲一区| 美女国产一区| 久久久久青草大香线综合精品| 欧美日韩你懂的| 免费日本视频一区| 国产婷婷精品| 亚洲欧美激情精品一区二区| 亚洲精品久久久久| 久久免费精品视频| 久久久久久综合| 国产精品自拍三区| 在线亚洲精品福利网址导航| 日韩午夜av电影| 欧美风情在线观看| 亚洲国产精品久久91精品| 在线观看欧美日韩国产| 欧美一区二区在线免费播放| 性欧美超级视频| 国产精品久久久久aaaa九色| 亚洲人成绝费网站色www| 亚洲国产精品久久久久秋霞蜜臀| 久久精品91久久久久久再现| 久久精品国产欧美激情| 国产色视频一区| 中文精品视频| 午夜视频一区| 国产欧美日韩亚洲| 欧美在线播放| 巨胸喷奶水www久久久免费动漫| 国产精品欧美经典| 午夜久久一区| 久久五月天婷婷| 在线日韩精品视频| 欧美电影免费| 亚洲开发第一视频在线播放| 亚洲视频国产视频| 国产精品黄色| 欧美一区网站| 欧美电影免费| 亚洲视屏在线播放| 国产精品五区| 久久免费视频一区| 亚洲精品综合久久中文字幕| 亚洲视频一区二区免费在线观看| 国产精品男gay被猛男狂揉视频| 亚洲一区图片| 欧美成人精品高清在线播放| 亚洲免费观看| 国产精品亚洲精品| 久久久久欧美| 99re6热在线精品视频播放速度| 亚洲欧美日韩精品在线| 尤物99国产成人精品视频| 欧美国产日韩一区二区在线观看| 9i看片成人免费高清| 久久一区二区三区四区| 亚洲免费观看视频| 国产视频亚洲| 欧美精品久久99| 欧美一区二视频在线免费观看| 亚洲丰满在线| 欧美主播一区二区三区美女 久久精品人| 激情成人综合网| 欧美三级电影精品| 久久久久久网站| 99精品国产在热久久下载| 老司机午夜精品视频| 夜夜嗨av一区二区三区四区| 国内偷自视频区视频综合| 欧美日韩色综合| 久久嫩草精品久久久精品| 亚洲永久在线观看| 最近中文字幕mv在线一区二区三区四区 | 久久手机免费观看| 亚洲婷婷在线| 亚洲人成毛片在线播放女女| 久久三级福利| 午夜电影亚洲| 国产精品99久久久久久久久| 亚洲国产精品一区| 国产区亚洲区欧美区| 欧美日韩色综合| 欧美大秀在线观看 | 亚洲电影av在线| 久久深夜福利免费观看| 亚洲欧美日韩一区在线观看| 99精品久久免费看蜜臀剧情介绍| 1024亚洲| 激情一区二区三区| 国产真实精品久久二三区| 国产精品视频久久久| 欧美日韩你懂的| 欧美日韩精品免费观看视频| 欧美成人亚洲成人| 欧美成人综合一区| 欧美二区视频| 欧美jizz19hd性欧美| 久久综合久久综合这里只有精品| 欧美中文字幕久久| 欧美中文字幕| 久久久久看片| 美国十次成人| 欧美激情综合色综合啪啪| 欧美国产第一页| 欧美日本中文字幕| 欧美日韩亚洲免费| 国产精品久久久久久久9999| 国产精品护士白丝一区av| 国产精品亚洲激情| 国产在线不卡| 亚洲国产精品一区制服丝袜| 亚洲高清不卡| 日韩视频在线播放| 亚洲尤物视频在线| 亚欧美中日韩视频| 久久亚洲国产精品日日av夜夜| 久久综合色88| 亚洲电影一级黄| 日韩午夜在线播放| 亚洲免费视频中文字幕| 性色av一区二区三区| 久久久91精品国产| 欧美精品一区二区视频| 欧美色大人视频| 国产欧美日韩专区发布| 亚洲福利国产| 一区二区三区四区五区在线| 午夜在线观看免费一区| 狂野欧美性猛交xxxx巴西| 亚洲福利视频二区| 亚洲一区二区三区久久| 久久一区二区视频| 欧美亚男人的天堂| ●精品国产综合乱码久久久久| 日韩亚洲精品在线| 久久久久久成人| 亚洲精品视频在线观看免费| 亚洲欧美在线另类| 欧美大片免费观看| 国产一区二区三区在线免费观看 | 夜夜嗨av一区二区三区中文字幕| 亚洲欧美在线网| 欧美国产激情| 久久aⅴ国产欧美74aaa| 欧美连裤袜在线视频| 国产欧美精品在线播放| 亚洲精品国偷自产在线99热| 欧美在线视频导航| 日韩亚洲欧美在线观看| 久久午夜电影网| 国产精品资源在线观看| 一本色道久久| 欧美成人一区在线| 久久不射网站| 国产美女精品|