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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? tour-ex1.html

?? 一個比較通用的大數運算庫
?? HTML
字號:
<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;

NTL_CLIENT

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>
Note the macro <tt>NTL_CLIENT</tt>.
When compiling NTL is ISO mode (the default), this
expands to 
<pre>
   using namespace std;
   using namespace NTL;
</pre>
When compiling NTL in traditional mode, this expands
to the empty string.

<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;

NTL_CLIENT

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;

NTL_CLIENT

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>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人中文字幕电影| 日本不卡一区二区| 国产成人亚洲综合色影视| 日韩免费高清av| 免费成人在线影院| 欧美电视剧免费全集观看| 激情综合色综合久久综合| 26uuu成人网一区二区三区| 国产综合色精品一区二区三区| 精品国产sm最大网站免费看| 国产精品123| 一区二区在线观看不卡| 欧美色区777第一页| 色一情一乱一乱一91av| 一区二区三区在线免费播放| 欧美日韩亚洲综合在线 | 免费精品视频在线| 久久久另类综合| 色呦呦日韩精品| 日韩黄色免费网站| 国产日韩欧美不卡在线| 99久久婷婷国产综合精品电影| 一区二区三区国产| 欧美一二三区在线观看| 成人综合婷婷国产精品久久| 亚洲自拍偷拍综合| 欧美不卡激情三级在线观看| 国产精品一级片| 亚洲一区二区三区小说| 精品国免费一区二区三区| 成人国产亚洲欧美成人综合网| 亚洲第一久久影院| 欧美激情综合在线| 欧美日本在线一区| 成人一区二区视频| 无码av中文一区二区三区桃花岛| 国产校园另类小说区| 欧美性猛交xxxxxxxx| 国产精品1024| 日韩专区一卡二卡| 亚洲天堂免费在线观看视频| 日韩欧美一级在线播放| 97精品国产露脸对白| 久久国产精品99久久久久久老狼 | 中文字幕一区二区三中文字幕 | 91精品国产综合久久小美女| 国产suv精品一区二区6| 日韩精品亚洲一区| 亚洲色图丝袜美腿| 久久精品夜色噜噜亚洲a∨| 欧美日韩国产不卡| 99久久婷婷国产综合精品| 美女视频一区二区| 亚洲va欧美va人人爽| 国产精品久久毛片a| 久久先锋影音av鲁色资源网| 欧美视频三区在线播放| 91小视频免费观看| 国产麻豆精品在线| 老司机午夜精品| 香蕉成人啪国产精品视频综合网| 亚洲欧美在线高清| 国产欧美一区二区精品婷婷| 精品久久久久久久人人人人传媒 | 国产精品影音先锋| 日韩和的一区二区| 一区二区三区四区乱视频| 国产精品欧美一区喷水| www国产精品av| 日韩女优视频免费观看| 欧美三级韩国三级日本一级| 色系网站成人免费| 色婷婷精品大视频在线蜜桃视频| 国产精品一卡二| 国产经典欧美精品| 国产麻豆成人传媒免费观看| 精品亚洲porn| 久草精品在线观看| 极品少妇xxxx偷拍精品少妇| 精品一区二区三区免费观看| 麻豆成人av在线| 看电视剧不卡顿的网站| 麻豆精品视频在线观看免费| 精品影视av免费| 韩国欧美一区二区| 懂色av一区二区在线播放| 国产91丝袜在线观看| 国产99一区视频免费| 成人黄色在线视频| av一区二区三区| 色婷婷亚洲精品| 欧美日韩三级在线| 8x福利精品第一导航| 欧美一级片在线看| 久久久一区二区| 亚洲国产精品精华液ab| 亚洲视频在线一区| 午夜精品久久一牛影视| 日本aⅴ亚洲精品中文乱码| 黑人巨大精品欧美黑白配亚洲| 国产一区二区成人久久免费影院| 国产精品自在在线| 一本色道久久加勒比精品| 欧美视频中文一区二区三区在线观看 | 国产午夜精品理论片a级大结局| 欧美国产欧美亚州国产日韩mv天天看完整 | 国产精品一卡二卡| 色综合网站在线| 欧美三级三级三级| 久久久美女毛片| 一区二区三区欧美视频| 日韩精彩视频在线观看| 国产成人在线色| 色爱区综合激月婷婷| 日韩区在线观看| 国产精品久久久久9999吃药| 亚洲国产日韩一级| 国产高清不卡一区| 欧美日韩一区二区在线观看| 精品电影一区二区| 亚洲美女在线一区| 久久99久久久久| 色综合色综合色综合| 日韩一区二区精品葵司在线| 亚洲欧洲日韩综合一区二区| 日韩精品一级中文字幕精品视频免费观看 | 国产成人免费在线观看不卡| 欧美性猛交xxxx黑人交| 久久精品日韩一区二区三区| 亚洲高清三级视频| 丰满少妇在线播放bd日韩电影| 在线观看日韩精品| 国产欧美一区二区精品秋霞影院| 午夜精品视频在线观看| av在线播放一区二区三区| 日韩欧美国产电影| 一区二区三区国产精品| 成人免费视频caoporn| 91精品国产一区二区三区| 亚洲欧美自拍偷拍| 国产精品主播直播| 日韩欧美国产综合| 亚洲一区二区五区| 成人深夜在线观看| 精品欧美乱码久久久久久| 亚洲大尺度视频在线观看| eeuss鲁片一区二区三区在线观看| 欧美成人精品3d动漫h| 亚洲一区二区在线观看视频| av成人免费在线观看| 精品国产一区久久| 日韩vs国产vs欧美| 欧美日韩的一区二区| 一区二区欧美国产| 99视频精品免费视频| 国产精品天干天干在观线| 精品一区二区三区视频在线观看| 欧美精品日韩一区| 亚洲制服丝袜一区| 色偷偷88欧美精品久久久| 国产欧美日产一区| 国内精品伊人久久久久影院对白| 欧美日韩电影一区| 午夜久久久久久久久久一区二区| 色哟哟精品一区| 一片黄亚洲嫩模| 色综合久久中文综合久久牛| 椎名由奈av一区二区三区| 成人美女视频在线观看18| 久久精品一区蜜桃臀影院| 国产精一品亚洲二区在线视频| 久久久久久麻豆| 国产老妇另类xxxxx| 久久伊人中文字幕| 国产成人免费高清| 国产欧美一区二区在线观看| 大白屁股一区二区视频| 中文字幕av一区二区三区免费看 | 成人黄色小视频在线观看| 国产精品理论片在线观看| 99久久免费精品高清特色大片| 中文字幕中文字幕一区| 91麻豆精品在线观看| 亚洲一区二区欧美日韩| 欧美在线免费视屏| 天天影视涩香欲综合网| 91精品国产综合久久国产大片| 久久66热re国产| 国产欧美精品一区| av在线不卡观看免费观看| 亚洲一区二区三区视频在线播放| 欧美精品一级二级三级| 免费观看久久久4p| 久久综合一区二区| av电影天堂一区二区在线观看| 亚洲精品视频一区二区| 91精品国产综合久久久久久久 | 久久天堂av综合合色蜜桃网| 成人精品电影在线观看| 亚洲精品日产精品乱码不卡|