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

C++研究

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

  C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
  37 隨筆 :: 0 文章 :: 74 評(píng)論 :: 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) 評(píng)論(8)  編輯 收藏 引用 所屬分類: Algorithm

評(píng)論

# 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ù)  更多評(píng)論
  

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

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

# 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ù)  更多評(píng)論
  

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

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

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

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

> 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>
            欧美中文字幕视频| 亚洲婷婷综合久久一本伊一区| 国产伦精品一区二区三区照片91| 亚洲国产你懂的| 老司机免费视频一区二区| 亚洲一区美女视频在线观看免费| 欧美精品v日韩精品v国产精品| 亚洲国产高清一区| 美女在线一区二区| 久久精品中文字幕一区二区三区 | 免费观看久久久4p| 国内精品美女在线观看| 久久狠狠久久综合桃花| 午夜国产精品视频免费体验区| 欧美午夜一区二区| 在线亚洲精品| 亚洲一区日韩| 国产一区二区成人| 久久亚洲不卡| 巨胸喷奶水www久久久免费动漫| 在线观看视频一区二区| 欧美激情中文字幕一区二区 | 99re66热这里只有精品4| 欧美国产高清| 欧美另类久久久品 | 午夜在线精品偷拍| 国产一区二区0| 欧美~级网站不卡| 欧美黄色免费网站| 亚洲性视频网站| 性做久久久久久免费观看欧美| 国内精品久久久久伊人av| 欧美大香线蕉线伊人久久国产精品| 欧美1区视频| 亚洲一线二线三线久久久| 午夜精品久久久99热福利| 亚洲视频在线免费观看| 中文日韩电影网站| 国产一区深夜福利| 欧美大色视频| 国产精品久久久久影院亚瑟| 久久久精品网| 欧美日韩国产综合视频在线观看| 亚洲欧美影音先锋| 久久精品一本久久99精品| 亚洲精品午夜| 午夜精品福利电影| 日韩视频在线一区| 午夜精品久久久久99热蜜桃导演| 亚洲第一黄色网| 亚洲网站在线| 亚洲国产视频一区| 亚洲欧美在线aaa| 日韩一区二区福利| 久久精品一区二区三区不卡牛牛 | 久久久久国产精品一区三寸 | 亚洲在线观看免费| 狂野欧美一区| 欧美一区91| 欧美日韩国产色视频| 久久天天躁狠狠躁夜夜爽蜜月| 欧美日韩一区二区免费视频| 久久亚洲午夜电影| 国产精品国产自产拍高清av| 欧美成人免费在线视频| 国产欧美高清| 一区二区电影免费在线观看| 亚洲国产导航| 久久精品国产亚洲一区二区三区 | 夜夜躁日日躁狠狠久久88av| 欧美自拍偷拍午夜视频| 亚洲欧美日韩视频二区| 欧美a级片网站| 蜜桃av一区二区| 国产亚洲欧美一区在线观看| 亚洲最新合集| 在线午夜精品自拍| 欧美精品在线观看91| 欧美高清在线精品一区| 黄色精品免费| 欧美在线精品免播放器视频| 欧美一区二区三区男人的天堂| 欧美日韩在线三级| 亚洲精品久久久蜜桃| 影音国产精品| 久久免费午夜影院| 免播放器亚洲| 亚洲缚视频在线观看| 久久久五月婷婷| 蜜臀av在线播放一区二区三区| 国语自产精品视频在线看8查询8| 亚洲欧美另类中文字幕| 欧美在线免费观看视频| 国产午夜精品视频免费不卡69堂| 亚洲男人第一av网站| 国产一区二区福利| 久久夜色精品国产亚洲aⅴ| 国产一二精品视频| 久久国产精品毛片| 老司机午夜精品视频在线观看| 国产一区观看| 久久久噜噜噜| 亚洲黄色av| 亚洲尤物在线视频观看| 国产精品毛片一区二区三区 | 在线成人黄色| 欧美成年网站| 一本色道久久综合| 欧美一区二粉嫩精品国产一线天| 国产欧美日韩综合精品二区| 午夜视频在线观看一区二区| 久久久久久久久久看片| 亚洲电影在线免费观看| 欧美激情精品久久久久久蜜臀| 亚洲美女黄色片| 欧美在线免费观看| 在线观看国产精品网站| 欧美大片在线观看| 亚洲一区二区久久| 免费日韩视频| 亚洲欧美精品伊人久久| 国产小视频国产精品| 猫咪成人在线观看| 一区二区三区产品免费精品久久75 | 亚洲图片你懂的| 国产在线播放一区二区三区| 久久综合中文字幕| 一区二区av在线| 免费在线观看日韩欧美| 一本色道久久综合亚洲精品婷婷| 国产精品日韩在线一区| 老牛国产精品一区的观看方式| 亚洲精品一区中文| 麻豆精品91| 亚洲欧美综合| 亚洲区欧美区| 国产综合视频在线观看| 欧美日韩国产一级| 久久久99精品免费观看不卡| 日韩网站在线观看| 另类综合日韩欧美亚洲| 亚洲午夜在线| 亚洲人精品午夜在线观看| 国产欧美精品在线| 欧美激情一区二区三区在线视频观看| 午夜日韩福利| 在线一区免费观看| 亚洲福利视频免费观看| 久久精品视频导航| 亚洲一区欧美二区| 亚洲精品无人区| 永久免费毛片在线播放不卡| 国产精品视频观看| 欧美三级网址| 欧美日韩国产美| 欧美不卡视频一区| 久久久久这里只有精品| 新狼窝色av性久久久久久| 一本色道久久88综合亚洲精品ⅰ| 亚洲高清三级视频| 欧美色播在线播放| 欧美.com| 亚洲在线一区二区| 99视频精品全国免费| 在线观看欧美精品| 国产综合自拍| 国产亚洲激情视频在线| 国产精品免费网站| 欧美午夜片在线免费观看| 欧美人成网站| 欧美日韩八区| 欧美日韩国产三级| 欧美日韩综合视频网址| 欧美日本韩国| 欧美日韩三区| 国产精品爱久久久久久久| 欧美日韩视频免费播放| 欧美日韩午夜剧场| 欧美色道久久88综合亚洲精品| 欧美日韩第一区日日骚| 欧美日韩在线不卡| 国产精品成人一区二区网站软件| 欧美日韩在线精品| 国产精品高潮久久| 国产欧美日韩综合精品二区| 国产欧美亚洲视频| 激情综合色综合久久| 影音先锋国产精品| 亚洲清纯自拍| 亚洲视频在线观看一区| 亚洲欧美在线一区二区| 久久av免费一区| 免费在线观看精品| 亚洲人成网站精品片在线观看| 亚洲最黄网站| 欧美一区二区三区日韩| 久久天天狠狠| 欧美日韩国产影院| 国产欧美在线视频| 亚洲第一精品在线|