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

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

?? tour-ex4.html

?? 大數運算類
?? HTML
字號:
<html>
<head>
<title>
A Tour of NTL: Examples: Modular Arithmetic </title>
</head>

<body bgcolor="#fff9e6">
<center>
<a href="tour-ex3.html"><img src="arrow1.gif" alt="[Previous]" align=bottom></a>
 <a href="tour-examples.html"><img src="arrow2.gif" alt="[Up]" align=bottom></a> 
<a href="tour-ex5.html"> <img src="arrow3.gif" alt="[Next]" align=bottom></a>
</center>

<h1> 
<p align=center>
A Tour of NTL: Examples: Modular Arithmetic
</p>
</h1>

<p> <hr> <p>


NTL also supports modular integer arithmetic.
The class <tt>ZZ_p</tt>
represents the integers mod <tt>p</tt>.
Despite the notation, <tt>p</tt> need not in general be prime,
except in situations where this is mathematically required.
The classes <tt>vec_ZZ_p</tt>, <tt>mat_ZZ_p</tt>,
and <tt>ZZ_pX</tt> represent vectors, matrices, and polynomials
mod <tt>p</tt>, and work much the same way as the corresponding
classes for <tt>ZZ</tt>.

<p>
Here is a program that reads a prime number <tt>p</tt>,
and a polynomial <tt>f</tt> modulo <tt>p</tt>, and factors it.

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

int main()
{
   ZZ p;
   cin &gt;&gt; p;
   ZZ_p::init(p);

   ZZ_pX f;
   cin &gt;&gt; f;

   vec_pair_ZZ_pX_long factors;

   CanZass(factors, f);

   cout &lt;&lt; factors &lt;&lt; "\n";
   // calls "Cantor/Zassenhaus" algorithm 
}
</pre>

<p>
As a program is running, NTL keeps track of a "current modulus"
for the class <tt>ZZ_p</tt>, which can be initialized or changed
using <tt>ZZ_p::init</tt>.
This must be done before any variables are declared or
computations are done that depend on this modulus.

<p>
Please note that for efficiency reasons,
NTL does not make any attempt to ensure that
variables declared under one modulus are not used
under a different one.
If that happens, the behavior of a program in this
case is completely unpredictable.


<p> <hr> <p>

Here are two more examples that illustrate the <tt>ZZ_p</tt>-related 
classes.
The first is a vector addition routine (already supplied by NTL):

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

void add(vec_ZZ_p&amp; x, const vec_ZZ_p&amp; a, const vec_ZZ_p&amp; b)
{
   long n = a.length();
   if (b.length() != n) Error("vector add: dimension mismatch");

   x.SetLength(n);
   long i;
   for (i = 0; i < n; i++)
      add(x[i], a[i], b[i]);
}
</pre>

<p>

The second example is an inner product routine (also supplied by NTL):

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

void InnerProduct(ZZ_p&amp; x, const vec_ZZ_p&amp; a, const vec_ZZ_p&amp; b)
{
   long n = min(a.length(), b.length());
   long i;
   ZZ accum, t;

   accum = 0;
   for (i = 0; i < n; i++) {
      mul(t, rep(a[i]), rep(b[i]));
      add(accum, accum, t);
   }

   conv(x, accum);
}
</pre>

<p>
This second example illustrates two things.
First, it illustrates the use of function <tt>rep</tt> which
returns a read-only reference to the representation of a <tt>ZZ_p</tt>
as a <tt>ZZ</tt> between <tt>0</tt> and <tt>p-1</tt>.
Second, it illustrates a useful algorithmic technique,
whereby one computes over <tt>ZZ</tt>, reducing mod <tt>p</tt>
only when necessary.
This reduces the number of divisions that need to be performed significantly,
leading to much faster execution.


<p>
The class <tt>ZZ_p</tt> supports all the basic arithmetic
operations in both operator and procedural form.
All of the basic operations support a "promotion logic",
promoting <tt>long</tt> to <tt>ZZ_p</tt>.

<p>
Note that the class <tt>ZZ_p</tt> is mainly useful only
when you want to work with vectors, matrices, or polynomials 
mod <tt>p</tt>.
If you just want to do some simple modular arithemtic,
it is probably easier to just work with <tt>ZZ</tt>s directly.
This is especially true if you want to work with many different
moduli:  modulus switching is supported, but it is a bit awkward.

<p>
The class <tt>ZZ_pX</tt> supports all the basic arithmetic
operations in both operator and procedural form.
All of the basic operations support a "promotion logic",
promoting both <tt>long</tt> and <tt>ZZ_p</tt> to <tt>ZZ_pX</tt>.

<p>
See <a href="ZZ_p.txt"><tt>ZZ_p.txt</tt></a> for details on <tt>ZZ_p</tt>;
see <a href="ZZ_pX.txt"><tt>ZZ_pX.txt</tt></a> for details on <tt>ZZ_pX</tt>;
see <a href="ZZ_pXFactoring.txt"><tt>ZZ_pXFactoring.txt</tt></a> for details on 
the routines for factoring polynomials over <tt>ZZ_p</tt>;
see <a href="vec_ZZ_p.txt"><tt>vec_ZZ_p.txt</tt></a> for details on <tt>vec_ZZ_p</tt>;
see <a href="mat_ZZ_p.txt"><tt>mat_ZZ_p.txt</tt></a> for details on <tt>mat_ZZ_p</tt>.

<p> <hr> <p>

There is a mechanism for saving and restoring a modulus,
which the following example illustrates.
This routine takes as input an integer polynomial
and a prime, and tests if the polynomial is irreducible modulo
the prime.

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

long IrredTestMod(const ZZX&amp; f, const ZZ&amp; p)
{
   ZZ_pBak bak;  // save current modulus in bak
   bak.save();

   ZZ_p::init(p);  // set the current modulus to p

   return DetIrredTest(to_ZZ_pX(f));

   // old modulus is restored automatically when bak is destroyed
   // upon return
}
</pre>

<p>
The modulus switching mechanism is actually quite a bit
more general and flexible than this example illustrates.

<p> 
The function <tt>to_ZZ_pX</tt> is yet another of NTL's many
conversion functions.
We could also have used the equivalent procedural form:
<pre>
   ZZ_pX f1;
   conv(f1, f);
   return DetIrredTest(f1);
</pre>






<p> <hr> <p>

Suppose in the above example that <tt>p</tt> is known in advance
to be a small, single-precision  prime.
In this case, NTL provides a class <tt>zz_p</tt>, that
acts just like <tt>ZZ_p</tt>,
along with corresponding classes <tt>vec_zz_p</tt>,
<tt>mat_zz_p</tt>, and <tt>zz_pX</tt>.
The interfaces to all of the routines are generally identical
to those for <tt>ZZ_p</tt>.
However, the routines are much more efficient, in both time and space.

<p>
For small primes, the routine in the previous example could be coded
as follows.


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

long IrredTestMod(const ZZX&amp; f, long p)
{
   zz_pBak bak; 
   bak.save();

   zz_p::init(p);  

   return DetIrredTest(to_zz_pX(f));
}
</pre>

<p> <hr> <p>

The following is a routine (essentially the same as implemented in NTL)
for computing the GCD of polynomials with integer coefficients.
It uses a "modular" approach:  the GCDs are computed modulo small
primes, and the results are combined using the Chinese Remainder Theorem (CRT).
The small primes are specially chosen "FFT primes", which are of
a special form that allows for particular fast polynomial arithmetic.

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

void GCD(ZZX&amp; d, const ZZX&amp; a, const ZZX&amp; b)
{
   if (a == 0) {
      d = b;
      if (LeadCoeff(d) &lt; 0) negate(d, d);
      return;
   }

   if (b == 0) {
      d = a;
      if (LeadCoeff(d) &lt; 0) negate(d, d);
      return;
   }

   ZZ c1, c2, c;
   ZZX f1, f2;

   content(c1, a);
   divide(f1, a, c1);

   content(c2, b);
   divide(f2, b, c2);

   GCD(c, c1, c2);

   ZZ ld;
   GCD(ld, LeadCoeff(f1), LeadCoeff(f2));

   ZZX g, res;

   ZZ prod;

   zz_pBak bak;
   bak.save();

   long FirstTime = 1;

   long i;
   for (i = 0; ;i++) {
      zz_p::FFTInit(i);
      long p = zz_p::modulus();

      if (divide(LeadCoeff(f1), p) || divide(LeadCoeff(f2), p)) continue;

      zz_pX G, F1, F2;
      zz_p  LD;

      conv(F1, f1);
      conv(F2, f2);
      conv(LD, ld);

      GCD(G, F1, F2);
      mul(G, G, LD);


      if (deg(G) == 0) { 
         res = 1;
         break;
      }

      if (FirstTime || deg(G) &lt; deg(g)) {
         prod = 1;
         g = 0;
         FirstTime = 0;
      }
      else if (deg(G) &gt; deg(g)) {
         continue;
      }

      if (!CRT(g, prod, G)) {
         PrimitivePart(res, g);
         if (divide(f1, res) &amp;&amp; divide(f2, res))
            break;
      }

   }

   mul(d, res, c);
   if (LeadCoeff(d) &lt; 0) negate(d, d);
}
</pre>


<p>
See <a href="lzz_p.txt"><tt>lzz_p.txt</tt></a> for details on <tt>zz_p</tt>;
see <a href="lzz_pX.txt"><tt>lzz_pX.txt</tt></a> for details on <tt>zz_pX</tt>;
see <a href="lzz_pXFactoring.txt"><tt>lzz_pXFactoring.txt</tt></a> for details on 
the routines for factoring polynomials over <tt>zz_p</tt>;
see <a href="vec_lzz_p.txt"><tt>vec_lzz_p.txt</tt></a> for details on <tt>vec_zz_p</tt>;
see <a href="mat_lzz_p.txt"><tt>mat_lzz_p.txt</tt></a> for details on <tt>mat_zz_p</tt>.



<p> <hr> <p>

Arithmetic mod 2 is such an important special case that NTL
provides a class <tt>GF2</tt>, that
acts just like <tt>ZZ_p</tt> when <tt>p == 2</tt>,
along with corresponding classes <tt>vec_GF2</tt>,
<tt>mat_GF2</tt>, and <tt>GF2X</tt>.
The interfaces to all of the routines are generally identical
to those for <tt>ZZ_p</tt>.
However, the routines are much more efficient, in both time and space.

<p>

This example illustrates the <tt>GF2X</tt> and <tt>mat_GF2</tt>
classes with a simple routine to test if a polynomial over GF(2)
is irreducible using linear algebra.
NTL's built-in irreducibility test is to be preferred, however.

<pre>

#include &lt;NTL/GF2X.h&gt;
#include &lt;NTL/mat_GF2.h&gt;

long MatIrredTest(const GF2X& f)
{
   long n = deg(f);

   if (n &lt;= 0) return 0;
   if (n == 1) return 1;

   if (GCD(f, diff(f)) != 1) return 0;

   mat_GF2 M;

   M.SetDims(n, n);

   GF2X x_squared = GF2X(2, 1);

   GF2X g;
   g = 1;

   for (long i = 0; i &lt; n; i++) {
      VectorCopy(M[i], g, n);
      M[i][i] += 1;
      g = (g * x_squared) % f;
   }

   long rank = gauss(M);

   if (rank == n-1)
      return 1;
   else
      return 0;
}
</pre>

<p>
Note that the statement 
<pre>
   g = (g * x_squared) % f;
</pre>
could be replace d by the more efficient code sequence
<pre>
   MulByXMod(g, g, f);
   MulByXMod(g, g, f);
</pre>
but this would not significantly impact the overall
running time, since it is the Gaussian elimination that 
dominates the running time.

<p>
See <a href="GF2.txt"><tt>GF2.txt</tt></a> for details on <tt>GF2</tt>;
see <a href="GF2X.txt"><tt>GF2X.txt</tt></a> for details on <tt>GF2X</tt>;
see <a href="GF2XFactoring.txt"><tt>GF2XFactoring.txt</tt></a> for details on 
the routines for factoring polynomials over <tt>GF2</tt>;
see <a href="vec_GF2.txt"><tt>vec_GF2.txt</tt></a> for details on <tt>vec_GF2</tt>;
see <a href="mat_GF2.txt"><tt>mat_GF2.txt</tt></a> for details on <tt>mat_GF2</tt>.

<p>

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

</body>
</html>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美性猛片aaaaaaa做受| 欧美a级一区二区| av电影在线观看一区| 国产精品毛片无遮挡高清| 国产激情视频一区二区三区欧美| 久久伊99综合婷婷久久伊| 国产精品一区专区| 欧美激情资源网| 在线观看视频一区| 日韩精品视频网站| 久久久久97国产精华液好用吗| 国产不卡高清在线观看视频| 亚洲欧美在线视频观看| 欧美日韩亚洲综合在线 欧美亚洲特黄一级| 亚欧色一区w666天堂| 日韩欧美国产成人一区二区| 成人污视频在线观看| 一区二区在线看| 日韩精品一区二区在线| 成人激情动漫在线观看| 午夜av电影一区| 欧美韩日一区二区三区四区| 91久久精品网| 国产一区日韩二区欧美三区| 中文字幕一区在线| 91精品福利在线一区二区三区| 国产一区二区在线看| 亚洲最新视频在线播放| 欧美成人一级视频| 91视频一区二区| 黑人巨大精品欧美一区| 亚洲一区二区免费视频| 久久免费视频一区| 欧美日韩专区在线| jizz一区二区| 精品夜夜嗨av一区二区三区| 最近日韩中文字幕| 久久综合色综合88| 欧美影院午夜播放| 成人av在线资源| 激情小说欧美图片| 亚洲福利一区二区三区| 国产欧美日韩中文久久| 欧美一区二区三级| 色欧美88888久久久久久影院| 国产在线精品一区二区| 午夜日韩在线观看| 亚洲欧美一区二区在线观看| 精品国产乱码久久久久久久| 欧美色国产精品| 91日韩一区二区三区| 国产精品一二三四五| 久久精品国产一区二区三区免费看| 亚洲老妇xxxxxx| 国产精品视频一区二区三区不卡| 欧美刺激午夜性久久久久久久| 欧美无人高清视频在线观看| www.综合网.com| 成人精品视频一区二区三区尤物| 九九精品一区二区| 毛片不卡一区二区| 日本va欧美va精品| 日韩精品久久理论片| 亚洲一区在线观看视频| 亚洲色图色小说| 国产精品成人在线观看| 中文字幕的久久| 国产精品情趣视频| 国产精品伦理在线| 国产精品狼人久久影院观看方式| 久久久国产精品麻豆| 久久精品视频免费| 国产色婷婷亚洲99精品小说| 久久先锋影音av鲁色资源| 精品三级在线观看| 久久这里只有精品6| 久久午夜羞羞影院免费观看| 久久综合久久久久88| 2023国产精华国产精品| 精品国产一二三| 久久久亚洲高清| 久久精品人人做| 国产精品久久看| 亚洲欧美韩国综合色| 亚洲黄色免费网站| 日韩不卡一二三区| 国产一区二区看久久| 成人一区二区三区中文字幕| eeuss鲁片一区二区三区| 91免费看`日韩一区二区| 在线亚洲一区观看| 91精品国产欧美一区二区18| 日韩欧美亚洲国产另类| 久久精品亚洲乱码伦伦中文| 国产精品视频看| 亚洲男人的天堂av| 石原莉奈一区二区三区在线观看| 蜜桃一区二区三区在线| 国产精品一区二区男女羞羞无遮挡 | 欧美极品aⅴ影院| 欧美国产1区2区| 亚洲影视资源网| 久久se这里有精品| av电影一区二区| 欧美丰满美乳xxx高潮www| 欧美成人福利视频| 一区二区中文字幕在线| 亚洲.国产.中文慕字在线| 久久成人综合网| 91婷婷韩国欧美一区二区| 在线综合视频播放| 国产精品国产三级国产| 丝袜美腿亚洲一区二区图片| 国产精品亚洲视频| 欧美日韩国产区一| 国产色91在线| 亚洲一区二区在线视频| 国产一区二区按摩在线观看| 99久久精品久久久久久清纯| 制服丝袜日韩国产| 国产精品二三区| 老司机免费视频一区二区| 91论坛在线播放| 久久影院午夜片一区| 亚洲午夜免费电影| 国产成人8x视频一区二区| 欧美日韩一区二区在线观看视频 | 久久久精品综合| 亚洲成a人片在线不卡一二三区| 国产一区二区不卡老阿姨| 欧美性一二三区| 亚洲欧美综合另类在线卡通| 国产综合一区二区| 911精品国产一区二区在线| 国产精品久久久久久亚洲毛片 | 懂色av一区二区三区蜜臀| 5566中文字幕一区二区电影| 国产精品毛片高清在线完整版| 久久99精品久久久久婷婷| 欧美私人免费视频| 中文字幕一区在线观看视频| 国产精品一区二区免费不卡 | 亚洲高清免费在线| 99久久伊人精品| 日本一区二区动态图| 国产在线播精品第三| 日韩欧美一区在线观看| 亚洲va欧美va人人爽| 蜜桃传媒麻豆第一区在线观看| 欧美综合一区二区三区| ㊣最新国产の精品bt伙计久久| 国产精品一区专区| 2020国产精品久久精品美国| 麻豆精品在线看| 日韩视频在线永久播放| 亚洲一区二区三区四区不卡| 99re视频精品| 亚洲欧美日韩久久精品| 波多野结衣亚洲| 国产精品色眯眯| 不卡的av在线播放| 中文字幕一区二区在线播放| 国产69精品久久久久777| 久久亚洲精品国产精品紫薇| 国产一区在线视频| 国产午夜精品久久久久久免费视| 国产九色sp调教91| 国产女主播一区| 国产 日韩 欧美大片| 欧美国产激情一区二区三区蜜月| 国产成人免费9x9x人网站视频| 久久久久青草大香线综合精品| 国产乱一区二区| 国产精品美女久久久久av爽李琼 | 欧美视频三区在线播放| 一区二区三区美女视频| 欧美性猛交一区二区三区精品| 亚洲国产aⅴ成人精品无吗| 91精品国产综合久久小美女| 喷水一区二区三区| 国产亚洲欧美色| 色系网站成人免费| 午夜精品久久久| 精品国产3级a| 成人app在线| 亚洲mv在线观看| 久久欧美一区二区| 97超碰欧美中文字幕| 亚洲777理论| 欧美精品一区二区三区一线天视频| 国产裸体歌舞团一区二区| 国产精品久久久99| 欧美日韩色一区| 国产一区三区三区| 亚洲乱码日产精品bd| 欧美二区在线观看| 国产激情精品久久久第一区二区| 亚洲欧美日韩人成在线播放| 3d成人动漫网站| 高清久久久久久|