MIRACL大数运算库使用手册(2014-4-15 10:52)


calc大数库,实现了所有的基本大数运算功能
http://www.pudn.com/downloads120/sourcecode/math/detail512532.html
calc_win32.exe的使用
          **************************
          * List of CALC functions *
          **************************
absmod, euclid, gcd, gcdv, gcda, gcdav, egcd, sgcd, lllgcd, lllgcd0,
lllhermite, axb, fp, slv, inhomfp, lcm, lcma, length,
pollard, nprime, nprimeap, jacobi, peralta, congr, chinese, chinesea,
mthroot, mthrootr, fund, pell, surd, mpower, inv, elliptic,
factor, tau, sigma, mobius, euler, lprimroot, orderm, lucas,
serret, collatz, cycle, miller, hermite, improvep, mlll, smith,
rsae, encode, decode, addcubicr, powercubicr, ordercubicr,
addcubicm, powercubicm, ordercubicm, convergents, lagrange,
perfectpower, leastqnr, content, primitive, sturm, rootexp, log,
sqroot, cornacchia, patz, congq, binform, ceil, testlog,
resultant, discriminant, deriv, primes, sturmsequence, cyclotomic,
classnop, classnon, nearint, reduceneg, reducepos, classnop0,
tableneg, tablepos, davison, raney, unimodular, twoadicsqrt,
padicsqrt, sigmak, ramanujan, repdefinite, powerd, euclid1.
          **************************
Type a function name or type qu to return to command line:qu
> euler 100
 syntax error
> euler(100)
40
> euler(1)
1

jacobi: usage: z=jacobi(x,y)
z is the value of the Jacobi symbol (x/y).
> jacobi(438,593)
-1
n=438是模数p=593的二次非剩余,即(438/593)=-1。
雅可比符号 (438 / 593 ) 的值为  -1
> jacobi(286,563)
-1
所以同余式x^2≡286(mod563)无解。

> lprimroot(41)
6
> orderm(6,41)
40
> orderm(7,41)
40
> orderm(11,41)
40
> orderm(12,41)
40
> orderm(13,41)
40
> orderm(15,41)
40
> orderm(17,41)
40
> orderm(19,41)
40
> orderm(22,41)
40
> orderm(24,41)
40
> orderm(26,41)
40
> orderm(28,41)
40
> orderm(29,41)
40
> orderm(30,41)
40
> orderm(34,41)
40
> orderm(35,41)
40

mpower: usage: z=mpower(a,b,c)
z=a^b(mod c) is returned.
a,b,c integers, b>=0,c>0.
> mpower(5,1,17)
5
> mpower(5,2,17)
8
> mpower(5,4,17)
13
> mpower(5,8,17)
16
> mpower(5,16,17)
1
> orderm(5,17)
16
整数5模17的指数ord_5(17)=16
整数a模m的指数ord_m(a)是φ(m)的因数,因此可在φ(m)的因数中求ord_m(a)。

大数的因数分解: 27606985387162255149739023449107931668458716142620601169954803000803329
如果求出来,告诉用时是多少。
PC:
64位Win7
CPU:i5-3470
RAM:8GB

其他人的:
27606985387162255149739023449107931668458716142620601169954803000803329
= (2^107-1)(2^127-1)
花了10分钟
27606 985387 162255 149739 023449 107931 668458 716142 620601 169954 803000 803329 = 162 259276 829213 363391 578010 288127 x 170 141183 460469 231731 687303 715884 105727

34864525345345373453453445748978532134534 = 2 x 11 x 23 x 191 x
360744628286171941450794091312403329
24536421389741586151534632715617654345354453321765107121732156751232652762136527621378346745323127213453213776523134534535
= 5 x 383 x 3739 x 30241 x
113315894134346081594070177001350118882036872051093104929569120420587225596613227523645898289491759297142685471
http://www.alpertron.com.ar/ECM.HTM
到这个网页来吧,专门进行因式分解。

 // 欧拉φ函数的程序计算
#if 1
 big x,y,z,totient;
 miracl *mip=mirsys(400,10);
 x=mirvar(1);
 y=mirvar(0);
 z=mirvar(0);
 totient=mirvar(0);
 //cinstr(y,"27606985387162255149739023449107931668458716142620601169954803000803329");
 //cinstr(y,"123456789012345678901234567890123456789");
 //cinstr(y,"12345678901234567890123456789");
 //cinstr(y,"1234567890123456789");
  cinstr(y,"123456789");//totient(123456789)=82260072,用时:258
 long long t1=time(0);
 if(compare(x,y)==0)
  totient=mirvar(1);//y=1,totient(1)=1,y=100,totient(100)=40
 else
 {
  while(compare(x,y)==-1)
  {
   int ret=egcd(x,y,z);
   if(ret==1)
    ret=1;
   else
    ret=0;
   incr(totient,ret,totient);//totient = totient + ret
   incr(x,1,x);        //x = x + 1
  }
 }
 cotnum(totient,stdout);
 long long t2=time(0);
 cout<<"用时:"<<(t2-t1)<<endl;
#endif


http://www.pudn.com/downloads101/sourcecode/windows/network/detail415020.html
关于mirac求大素数的原根 http://www.mathmagic.cn/bbs/read.php?tid=11739&fpage=3
在VC2010工程的附加包含目录添加D:\SixDivisions\GoodFRame\Miracl\Miracl
新建筛选器,命名为大数库
将D:\SixDivisions\GoodFRame\Miracl\Miracl
目录下的所有.h,.c文件添加到当前工程的这个筛选器下
添加如下测试代码,运行出现如下结果:
19
79
2
5DD
#include<stdlib.h>
extern "C"
{
#include"miracl.h"
#include"mirdef.h"
}
int main()
{
    miracl *mip =mirsys(400,10);   //初始化一个400位10进制的大数系统
    big x,y,z;
    x = mirvar(177);
    y = mirvar(79);
    z = mirvar(0);
    divide(x, y, z);  //x=x mod y, z=x/y
    cotnum(x,stdout); //x=19
    cotnum(y,stdout); //y=79
    cotnum(z,stdout); //z=2
    multiply(x, y, z);   //z=x*y
    mip->IOBASE=16;      //将原来的10进制改为16进制模式
    cotnum(z, stdout);   //5DD
    mirkill(x);          //释放大数变量
    mirkill(y);
    mirkill(z);
    system("pause");
    return 0;
}
1903年
2^67-1=147 573 952 589 676 412 927
193 707 721×761 838 257 287=147 573 952 589 676 412 927
please input two bignums:
193707721
761838257287
147573952589676412927

170!=Verylongfactorial(170)=725741561530799896739672821112926311471699168129645137654357779890056184340170615785235074924261745951149099123783852077666602256544275302532890077320751090240043028005829560396661259965825710439855829425756896631343961226257109494680671120556888045719334021266145280000000000000000000000000000000
0000000000是一个306位的整数
factorial program
input number n=
170
n!=
72574156153079989673967282111292631147169916812964513765435777989005618434017061
57852350749242617459511490991237838520776666022565442753025328900773207510902400
43028005829560396661259965825710439855829425756896631343961226257109494680671120
5568880457193340212661452800000000000000000000000000000000000000000

2^100结果为:
1267650600228229401496703205376
2^100-1=1267650600228229401496703205375

#if 1
 miracl *mip=mirsys(5000,16);
 //int n=0;
 //printf("input number n= \n");  
 //scanf("%d",&n);
 for(int n=0;n<=10;n++)
 {
  big x,y;
  x=mirvar(0);
  y=mirvar(0);
  expb2(n,x);   //2^n=x
  char sz[40]={0};
  int len=cotstr(x,sz);
  int m=atoi(sz);
  expb2(m,y);   //2^m=y
  incr(y,1,y);        //y = y + 1
  cotnum(y,stdout);   //输出到屏幕 
  //还是测试一下是否为素数   
  if(isprime(y) )
   std::cout<<"y=F_"<<n<<" is a prime!"<<"\n";
 }
#endif
猜想:只有3、5、17、257、65537这5个费马素数存在。
1640年,费马在研究素数性质时,发现了一个有趣的现象:
2^(2^n)+1=F_n
当n=1时,F_1=5;
当n=2时,F_2=17;
当n=3时,F_3=257;
当n=4时,F_4=65537;
猜测:只要n是自然数, F_n一定是素数
 1732年,欧拉进行了否定
3
y=F_0 is a prime!
5
y=F_1 is a prime!
17
y=F_2 is a prime!
257
y=F_3 is a prime!
65537
y=F_4 is a prime!
4294967297
18446744073709551617
340282366920938463463374607431768211457
115792089237316195423570985008687907853269984665640564039457584007913129639937
13407807929942597099574024998205846127479365820592393377723561443721764030073546
976801874298166903427690031858186486050853753882811946569946433649006084097
17976931348623159077293051907890247336179769789423065727343008115773267580550096
31327084773224075360211201138798713933576587897688144166224928474306394741243777
67893424865485276302219601246094119453082952085005768838150682342462881473913110
540827237163350510684586298239947245938479716304835356329624224137217

验证费马小定理
如果p是一个素数,那么对于任何自然数n,n^p-n一定能够被p整除
利用费马小定理,是目前最有效的鉴定素数的方法
#if 1
 big x,y;
 miracl *mip=mirsys(5000,16);
 x=mirvar(0);
 y=mirvar(0);
 int  Primes[5]={2,3,5,17,257};
 int  Ints[4]={3,10,8,9};
 for(int p=0;p<5;p++)
 for(int i=0;i<4;i++)
 {
  expint(Ints[i], Primes[p],x);
  decr(x,Ints[i],x);        //x = x - n
  BOOL iRet=subdivisible(x,Ints[i]);
  if(iRet==1)
  { 
   std::cout<<Ints[i]<<"能整除";
   cotnum(x,stdout);
   std::cout<<",商为";
   int r=subdiv(x,Ints[i],y);
   cotnum(y,stdout);
   std::cout<<",余数为"<<r<<"\n";
  }
  else
   std::cout<<"不能整除"<<"\n";
 }
#endif
3能整除6
,商为2
,余数为0
10能整除90
,商为9
,余数为0
8能整除56
,商为7
,余数为0
9能整除72
,商为8
,余数为0
3能整除24
,商为8
,余数为0
10能整除990
,商为99
,余数为0
8能整除504
,商为63
,余数为0
9能整除720
,商为80
,余数为0
3能整除240
,商为80
,余数为0
10能整除99990
,商为9999
,余数为0
8能整除32760
,商为4095
,余数为0
9能整除59040
,商为6560
,余数为0
3能整除129140160
,商为43046720
,余数为0
10能整除99999999999999990
,商为9999999999999999
,余数为0
8能整除2251799813685240
,商为281474976710655
,余数为0
9能整除16677181699666560
,商为1853020188851840
,余数为0
3能整除4170253571314341982948193603689839093426565524255874139748144732901082178
89299307823005307462328828565434996621646698306560
,商为139008452377144732764939786789661303114218850808529137991604824430036072629
766435941001769154109609521811665540548899435520
,余数为0
10能整除999999999999999999999999999999999999999999999999999999999999999999999999
99999999999999999999999999999999999999999999999999999999999999999999999999999999
99999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999990
,商为999999999999999999999999999999999999999999999999999999999999999999999999999
99999999999999999999999999999999999999999999999999999999999999999999999999999999
99999999999999999999999999999999999999999999999999999999999999999999999999999999
999999999999999999999
,余数为0
8能整除1242014473840567148119183590770002044205508813693357288911241630420840762
14910150906470272706291718236039018455770485856493726403529185151315542982003294
49113635639808166799244402122285052787558602103993549731750007142774830528462840
,商为155251809230070893514897948846250255525688601711669661113905203802605095268
63768863308784088286464779504877306971310732061715800441148143914442872750411811
39204454976020849905550265285631598444825262999193716468750892846853816057855
,余数为0
9能整除1739101484906002359490866184981762294986131918544299569516608386601222007
17739833000161454868074264189510740963651275075546381581911996467956882364308557
75588304495120354659534500256090166635104308939059701418048932612354193087294695
7451928872960
,商为193233498322889151054540687220195810554014657616033285501845376289024667464
15537000017939429786029354390082329294586119505153509101332940884098040478728639
54256055013372739948277806232240737233812104339966824227659179150465898588299527
2436541440
,余数为0

你可能感兴趣的:(MIRACL大数运算库使用手册(2014-4-15 10:52))