亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? tour-ex1.html

?? 大數(shù)運(yùn)算類(lèi)
?? HTML
字號(hào):
<html>
<head>
<title>
A Tour of NTL: Examples: Big Integers </title>
</head>

<body bgcolor="#fff9e6">

<center>
<img src="arrow1.gif" alt="[Previous]" align=bottom>
 <a href="tour-examples.html"><img src="arrow2.gif" alt="[Up]" align=bottom></a> 
<a href="tour-ex2.html"> <img src="arrow3.gif" alt="[Next]" align=bottom></a>
</center>

<h1> 
<p align=center>
A Tour of NTL: Examples: Big Integers
</p>
</h1>

<p> <hr>  <p>

The first example makes use of the class
<tt>ZZ</tt>,
which
represents "big integers": signed, arbitrary length integers.
This program reads two big integers <tt>a</tt> and <tt>b</tt>,
and prints <tt>(a+1)*(b+1)</tt>.

<p>
<pre>
#include &lt;NTL/ZZ.h&gt;

int main()
{
   ZZ a, b, c; 

   cin &gt;&gt; a; 
   cin &gt;&gt; b; 
   c = (a+1)*(b+1);
   cout &lt;&lt; c &lt;&lt; "\n";
}
</pre>

<p>

This program declares three variables <tt>a</tt>, <tt>b</tt>,
and <tt>c</tt> of type <tt>ZZ</tt>.
The values <tt>a</tt> and <tt>b</tt> are read from standard input.
The value <tt>c</tt> is then computed as <tt>(a+1)*(b+1)</tt>.
Finally, the value of <tt>c</tt> is printed to the standard output.

<p>
Note that one can compute with <tt>ZZ</tt>s much as with ordinary
<tt>int</tt>s, in that most of the standard arithmetic and
assignment operators can be used in a direct and natural way.
The <tt>C++</tt> compiler and the NTL library routines 
automatically take care
of all the bookkeeping involved
with memory management and temporary objects.

<p> <hr> <p>

Here's a program that reads a list of integers from standard 
input and prints the sum of their squares.

<p>
<pre>
#include &lt;NTL/ZZ.h&gt;

int main()
{
   ZZ acc, val;

   acc = 0;
   while (SkipWhiteSpace(cin)) {
      cin &gt;&gt; val;
      acc += val*val;
   }

   cout &lt;&lt; acc &lt;&lt; "\n";
}
</pre>

<p>

The function <tt>SkipWhiteSpace</tt> is defined by NTL.
It skips over white space, and returns 1 if there is something
following it.
This function is useful, because
NTL's input operators raise an error if an input
is missing or ill-formed. 
This is different from the standard I/O library,
which does not raise an error.
Personally, I find that not raising an error, or at least
an exception, is a bad idea, since the caller of the I/O
routine must constantly check the status of the input
stream.




<p>
<hr>
<p>

Here's a simple modular exponentiation routine for computing
<tt>a^e mod n</tt>.
NTL already provides a more sophisticated one, though.

<p>
<pre>
ZZ PowerMod(const ZZ&amp; a, const ZZ&amp; e, const ZZ&amp; n)
{
   if (e == 0) return to_ZZ(1);

   long k = NumBits(e);

   ZZ res;
   res = 1;

   for (long i = k-1; i &gt;= 0; i--) {
      res = (res*res) % n;
      if (bit(e, i) == 1) res = (res*a) % n;
   }

   if (e &lt; 0)
      return InvMod(res, n);
   else
      return res;
}
</pre>
<p>

Note that as an alternative, we could implement the inner loop
as follows:

<pre>
   res = SqrMod(res, n);
   if (bit(e, i) == 1) res = MulMod(res, a, n);
</pre>

We could also write this as:

<pre>
   SqrMod(res, res, n);
   if (bit(e, i) == 1) MulMod(res, res, a, n);
</pre>

This illustrates an important point about NTL's programming interface.
For every function in NTL, there is a procedural version that
stores its result in its first argument.
The reason for using the procedural variant is efficieny:
on every iteration through the above loop, the functional form
of <tt>SqrMod</tt> will cause a temporary <tt>ZZ</tt> object to
be created and destroyed, whereas the procedural version 
will not create any temporaries.
Where performance is critical, the procedural version
is to be preferred.
Although it is usually silly to get too worked up about performance,
it may be reasonable to argue that modular exponentiation
is an important enough routine that it should be as fast as possible.

<p>

Note that when the functional version of a function
can be naturally named with an operator, this is done.
So for example, NTL provides a 3-argument <tt>mul</tt> routine
for <tt>ZZ</tt> multiplication, and a functional version
whose name is <tt>operator *</tt>, and not <tt>mul</tt>.

<p>

While we are taking about temporaries, consider the first version
of the inner loop.
Execution of the statement
<pre>
   res = (res*res) % n;
</pre>
will result in the creation of two temporary objects,
one for the product, and one for the result of the mod operation,
whose value is copied into <tt>res</tt>.
Of course, the compiler automatically generates the code for
cleaning up temporaries and other local objects at the right time.
The programmer does not have to worry about this.


<p> <hr> <p>

This example is a bit more interesting.
The following program prompts the user for an input,
and applies a simple probabilistic primality test.
Note that NTL already provides a slightly more sophisticated
prime test.

<p>
<pre>
#include &lt;NTL/ZZ.h&gt;

long witness(const ZZ&amp; n, const ZZ&amp; x)
{
   ZZ m, y, z;
   long j, k;

   if (x == 0) return 0;

   // compute m, k such that n-1 = 2^k * m, m odd:

   k = 1;
   m = n/2;
   while (m % 2 == 0) {
      k++;
      m /= 2;
   }

   z = PowerMod(x, m, n); // z = x^m % n
   if (z == 1) return 0;

   j = 0;
   do {
      y = z;
      z = (y*y) % n; 
      j++;
   } while (j &lt; k &amp;&amp; z != 1);

   return z != 1 || y != n-1;
}


long PrimeTest(const ZZ&amp; n, long t)
{
   if (n &lt;= 1) return 0;

   // first, perform trial division by primes up to 2000

   PrimeSeq s;  // a class for quickly generating primes in sequence
   long p;

   p = s.next();  // first prime is always 2
   while (p && p < 2000) {
      if ((n % p) == 0) return (n == p);
      p = s.next();  
   }

   // second, perform t Miller-Rabin tests

   ZZ x;
   long i;

   for (i = 0; i &lt; t; i++) {
      x = RandomBnd(n); // random number between 0 and n-1

      if (witness(n, x)) 
         return 0;
   }

   return 1;
}

int main()
{
   ZZ n;

   cout &lt;&lt; "n: ";
   cin &gt;&gt; n;

   if (PrimeTest(n, 10))
      cout &lt;&lt; n &lt;&lt; " is probably prime\n";
   else
      cout &lt;&lt; n &lt;&lt; " is composite\n";
}
</pre>
<p>

Note that in NTL, there are typically a number of ways to
compute the same thing.
For example, consider the computation of <tt>m</tt> and <tt>k</tt>
in function <tt>witness</tt>.
We could have written it thusly:

<pre>
   k = 1;
   m = n &gt;&gt; 1;
   while (!IsOdd(m)) {
      k++;
      m &gt;&gt;= 1;
   }
</pre>

It turns out that this is actually not significantly more 
efficient than the original version, because the implementation
optimizes multiplication and division by 2.

<p>

The following is more efficient:

<pre>
   k = 1;
   while (bit(n, k) == 0) k++;
   m = n &gt;&gt; k;
</pre>

As it happens, there is a built-in NTL routine that does just what we want:

<pre>
   m = n-1;
   k = MakeOdd(m);
</pre>



<p> <hr> <p>

Having seen a number of examples involving <tt>ZZ</tt>s,
let's look at the <tt>ZZ</tt> interface in a bit more detail.

<p>

<b>
Constructors, assignment, and conversions
</b>

<p>

When you declare an object of type <tt>ZZ</tt>, 
the default constructor initializes to the value <tt>0</tt>.
As we have already seen, there is an assignment operator that
allows one to copy the value of one <tt>ZZ</tt> to another.
Note that these copies (like almost all copies in NTL) are "deep",
i.e., the actual data is copied, and not just a pointer.
Of course, if the amount of space allocated by the destination
of the assignment is insufficient to hold the value of the source,
space is automatically re-allocated.

<p>
One can also assign a value of type <tt>long</tt> to a <tt>ZZ</tt>:
<pre>
   ZZ x;
   x = 1;
</pre>

<p>
Note that one cannot write
<pre>
   ZZ x = 1;  // error
</pre>
to initialize a <tt>ZZ</tt>.
As a design principle, NTL avoids implicit conversions, and unfortunately,
the only way to allow initializations like this in <tt>C++</tt>
is to define an implicit conversion operator.
Instead, one could write
<pre>
   ZZ x = to_ZZ(1);
</pre>
This is an example of one of NTL's conversion routines.
For very large constants, one can write:
<pre>
   ZZ x = to_ZZ("99999999999999999999");
</pre>
These examples illustrate conversion rountines in their 
functional forms.
The corresponding procedural forms are all called <tt>conv</tt>, e.g.,
<pre>
   ZZ x;
   conv(x, 1);
   conv(x, "99999999999999999999");
</pre>

<p>
<b>
Functionality
</b>
<p>

All of the basic arithmetic operators are supported,
including comparison, arithmetic, shift, and bit-wise logical operations.
One can mix <tt>ZZ</tt>s and <tt>long</tt>s in any expresion in
a natural way.
As was already mentioned, NTL does not support implicit type conversion;
rather, for basic operations, it simply overloads the operators
or functions in a way to achieve a kind of "promotion logic":
if one input is a <tt>ZZ</tt> and the other is a <tt>long</tt>
(or something that implicitly converts to a <tt>long</tt>, like 
an <tt>int</tt>), the <tt>long</tt> input is effectively converted
to a <tt>ZZ</tt>.
Moreover, wherever possible, the implementation does this 
as efficiently as possible, and usually avoids the creation
of a temporary <tt>ZZ</tt>.

<p>
There are also procedural versions for all the basic arithmetic
operations:
<pre>
   add, sub, negate, mul, sqr, div, rem, DivRem, 
   LeftShift, RightShift,
   bit_and, bit_or, bit_xor
</pre>

<p>
There are many other routines.
Here is a brief summary:
<ul>
<li>
<tt>GCD</tt> -- computes greatest common divisor of two integers
<li>
<tt>XGCD</tt> -- extended Euclidean algorithm
<li>
<tt>AddMod</tt>, <tt>SubMod</tt>, <tt>NegateMod</tt>, 
<tt>MulMod</tt>, <tt>SqrMod</tt>, <tt>InvMod</tt>,
<tt>PowerMod</tt> -- routines for modular arithmetic,
including inversion and exponentiation
<li>
<tt>NumBits</tt> -- length of binary representation
<li>
<tt>bit</tt> -- extract a bit
<li>
<tt>ZZFromBytes</tt>, <tt>BytesFromZZ</tt> -- 
convert between octet strings and <tt>ZZ</tt>s
<li>
<tt>RandomBnd</tt>, <tt>RandomBits</tt>, <tt>RandomLen</tt> --
routines for generating pseudo-random numbers
<li>
<tt>GenPrime</tt>, <tt>ProbPrime</tt> -- routines for generating primes
and testing primality
<li>
<tt>power</tt> -- (non-modular) exponentiation
<li>
<tt>SqrRoot</tt> -- integer part of square root
<li>
<tt>Jacobi</tt>, <tt>SqrRootMod</tt> -- Jacobi symbol and modular
square root
</ul>

<p>
Most of these functions also have pure <tt>long</tt> versions as 
well, and as usual, there are both functional and procedural
variants.

<p>
There are other functions as well.
See <a href="ZZ.txt"><tt>ZZ.txt</tt></a> for complete details.
Also see <a href="tools.txt"><tt>tools.txt</tt></a> for some basic
services provided by NTL.


<p>
<center>
<img src="arrow1.gif" alt="[Previous]" align=bottom>
 <a href="tour-examples.html"><img src="arrow2.gif" alt="[Up]" align=bottom></a> 
<a href="tour-ex2.html"> <img src="arrow3.gif" alt="[Next]" align=bottom></a>
</center>

</body>
</html>

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91久久精品一区二区三| 91精品在线观看入口| 午夜精品久久久久| 久久精品网站免费观看| 欧美一区二区成人| 日本精品视频一区二区| 国产一区二区调教| 香蕉久久一区二区不卡无毒影院 | 日韩免费成人网| 91美女蜜桃在线| 国产一区视频导航| 日韩av一级电影| 夜夜夜精品看看| 国产精品妹子av| 久久午夜电影网| 欧美一级片在线| 欧美日韩激情在线| 日本韩国欧美国产| www..com久久爱| 国产电影精品久久禁18| 久久国产欧美日韩精品| 午夜精品一区在线观看| 一区二区三区在线影院| 国产精品成人免费精品自在线观看| 欧美xxxxx裸体时装秀| 欧美日本在线观看| 欧美天堂亚洲电影院在线播放| www.视频一区| 成人免费看片app下载| 国产传媒一区在线| 国产伦精品一区二区三区免费迷 | 一本久道久久综合中文字幕| 成人精品鲁一区一区二区| 国产一区二区在线观看视频| 国内精品在线播放| 国产一区二区三区在线观看免费 | 欧美一区二区免费观在线| 欧美日韩中文精品| 欧美理论片在线| 91.xcao| 91精品国产欧美一区二区成人| 欧美日韩高清影院| 欧美日韩五月天| 欧美欧美欧美欧美首页| 51精品国自产在线| 日韩三区在线观看| 欧美成va人片在线观看| 日韩欧美精品在线视频| 精品免费99久久| 国产亚洲精品精华液| 欧美国产精品久久| 亚洲欧美一区二区三区孕妇| 亚洲一区二区三区四区五区黄| 亚洲午夜国产一区99re久久| 五月婷婷另类国产| 久久99久久99精品免视看婷婷| 黄色日韩网站视频| 波多野结衣在线aⅴ中文字幕不卡| 99久久国产免费看| 欧美视频一区二| 91精品国产色综合久久不卡蜜臀| 精品欧美久久久| 亚洲欧洲日韩一区二区三区| 亚洲精品中文字幕在线观看| 亚洲1区2区3区4区| 国产一区二区久久| 色综合欧美在线视频区| 911精品产国品一二三产区| 久久精品免费在线观看| 日韩美女精品在线| 婷婷国产v国产偷v亚洲高清| 国内精品伊人久久久久av一坑| 99久久免费国产| 欧美剧情片在线观看| 久久久蜜桃精品| 一区二区三区在线免费视频 | 91久久精品一区二区| 91精品国产丝袜白色高跟鞋| 国产欧美一区二区三区网站| 一区二区三区四区高清精品免费观看 | 亚洲欧美精品午睡沙发| 全国精品久久少妇| 99久久伊人精品| 日韩一区二区在线看片| 亚洲欧洲在线观看av| 免费人成网站在线观看欧美高清| 不卡的看片网站| 精品日本一线二线三线不卡| 一区二区在线看| 国产成人鲁色资源国产91色综 | 国产精品白丝av| 欧美喷潮久久久xxxxx| 国产精品视频一区二区三区不卡| 性做久久久久久免费观看欧美| 国产成人aaa| 日韩网站在线看片你懂的| 亚洲日本va在线观看| 韩国视频一区二区| 欧美色区777第一页| 国产精品无码永久免费888| 日本91福利区| 在线观看免费成人| 中文字幕一区在线观看视频| 激情文学综合网| 欧美绝品在线观看成人午夜影视| 1024国产精品| 国产精品123| 日韩一区二区三区在线| 一区二区三区欧美在线观看| 丁香激情综合国产| 久久综合久久综合亚洲| 调教+趴+乳夹+国产+精品| 色综合婷婷久久| 国产精品久久久久影院色老大| 狠狠色综合日日| 欧美一区二区在线免费观看| 亚洲一区二区三区四区在线观看 | 欧美日韩国产一级片| 一区二区激情视频| av激情成人网| 国产欧美一区二区在线| 国产精品一二三| 久久久亚洲精华液精华液精华液| 久久99热这里只有精品| 欧美一级免费观看| 日韩电影在线免费| 69堂成人精品免费视频| 日韩不卡手机在线v区| 欧美日韩国产一级片| 午夜国产精品一区| 欧美伦理影视网| 日本va欧美va欧美va精品| 欧美日本一区二区| 婷婷久久综合九色综合绿巨人| 欧美日韩中文另类| 日韩黄色片在线观看| 欧美日韩午夜影院| 青娱乐精品视频| 欧美一级片在线观看| 久久精品国产在热久久| 欧美不卡激情三级在线观看| 精品一区二区三区免费观看| 精品福利在线导航| 国产一区二区福利| 中文字幕永久在线不卡| 一本久久综合亚洲鲁鲁五月天 | 精品福利在线导航| 国产成人午夜片在线观看高清观看| 久久久久国产精品麻豆ai换脸| 国内精品久久久久影院色 | 亚洲视频一二区| 色一情一伦一子一伦一区| 亚洲一区二区三区在线看| 欧美日韩成人综合天天影院 | 国产精品青草久久| 99久久久无码国产精品| 亚洲国产一区二区三区| 日韩亚洲国产中文字幕欧美| 国产精品综合在线视频| 成人欧美一区二区三区小说| 欧美性猛交一区二区三区精品| 日韩av一级片| 欧美韩国日本不卡| 在线精品亚洲一区二区不卡| 日韩主播视频在线| 久久女同精品一区二区| 色综合天天综合| 奇米色一区二区| 国产精品每日更新在线播放网址 | 成人av电影在线| 午夜伦理一区二区| 久久久久免费观看| 在线看国产一区二区| 国模套图日韩精品一区二区 | 国产精品色一区二区三区| 在线日韩av片| 黑人精品欧美一区二区蜜桃| 亚洲免费在线视频| 精品久久久久久久久久久院品网 | 91免费在线播放| 美腿丝袜一区二区三区| 国产精品福利一区| 3d动漫精品啪啪| 成人av高清在线| 久久疯狂做爰流白浆xx| 亚洲另类在线视频| 久久亚洲一级片| 欧美精品黑人性xxxx| 99热这里都是精品| 韩国v欧美v亚洲v日本v| 亚洲成av人片观看| 国产精品三级久久久久三级| 91精品国产综合久久小美女| 91日韩一区二区三区| 极品美女销魂一区二区三区| 亚洲一区精品在线| ㊣最新国产の精品bt伙计久久| 欧美一级欧美三级在线观看| 欧美综合一区二区三区| 成人免费看片app下载|