数论及应用之总结提纲

(一)GCD、LCM

1.GCD、LCM

ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

2.扩展欧几里得算法:求等式ax+by=gcd(a,b)中的x,y;返回d=gcd(a,b)

ll extended_gcd(ll a,ll b,ll &x,ll &y)//扩展欧几里得算法:求等式ax+by=gcd(a,b)中的x,y;返回d=gcd(a,b)
{
    if(b==0) {x=1;y=0;return a;} //边界a*1+0*0=gcd(a,0)=a;
    ll d=extended_gcd(b,a%b,y,x);
    y-=a/b*x;
    return d;
}

(二)素数问题

1.筛法

bool isprime[maxn];
void make_prime()
{
    k=0;
    memset(isprime,true,sizeof(isprime));
    for(int i=2;i*i<=maxn;i++)
    if(isprime[i]){
      prime[k++]=i;
      for(int j=i+i;j
   
   

2.Miller-Rabin素数测试(判断大数n是否为素数)

ll random(ll n){return (ll)((double)rand()/RAND_MAX*n+0.5);}
ll multi(ll a,ll b,ll mod)
{
    ll ans=0;
    while(b){
        if(b&1) ans=(ans+a)%mod;
        b>>=1;
        a=(a+a)%mod;
    }
    return ans;
}
ll quickpow_mod(ll a,ll b,ll mod)
{
    ll ans=1;
    while(b){
        if(b&1) ans=multi(ans,a,mod);
        b>>=1;
        a=multi(a,a,mod);
    }
    return ans;
}
bool Witness(ll a,ll n)
{
    ll m=n-1;
    int j=0;
    while(!(m&1)){
        j++;
        m>>=1;
    }
    ll x=quickpow_mod(a,m,n);
    if(x==1||x==n-1) return false;
    while(j--){
        x=x*x%n;
        if(x==n-1) return false;
    }
    return true;
}
bool Miller_rabin(ll n)
{
    if(n<2) return false;
    else if(n==2) return true;
    else if(!(n&1)) return false;
    for(int i=0;i
    
    

3.整数分解

算法一:试除法

void divide(ll n)
{
    t=0;
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            fac[t++]=i;
            n/=i;
            while(n%i==0)  {
              fac[t++]=i;
              n/=i;
            }
        }
    }
    if(n!=1) fac[t++]=n;
}
算法二:筛选法

void make_prime()
{
    k=0;
    memset(isprime,true,sizeof(isprime));
    for(int i=2;i*i<=maxn;i++)
    if(isprime[i]){
      prime[k++]=i;
      for(int j=i+i;j
     
     
      < code>
     
算法三:Pollard_rho大整数分解法

ll pollard_rho(ll n,int c)
{
    ll x,y,d,i=1,k=2;
    x=random(n-1)+1;
    y=x;
    while(1){
        i++;
        x=(multi(x,x,n)+c)%n;
        d=gcd(y-x,n);
        if(1
      
      
       
       
        
        =n) p=pollard_rho(p,k--);
    find(p,k);
    find(n/p,k);
}

       
       
      
      

4.n!素因子分解中素数p的幂为[n/p]+[n/p^2]+[n/p^3]+[n/p^4]+……

int n;
int solve(int p)
{
   int cnt=0;
   int q=p;
   while(q<=n){
    cnt+=n/q;
    q*=p;
   }
   return cnt;
}

5.梅森素数判定

(1)梅森素数表

#include 
      
      
       
       
#include 
       
       
        
        
#include 
        
        
         
         
#include 
         
         
#include 
          
          
            #include 
           
             #include 
            
              using namespace std; const int maxn=50000+10; int p,Mp[9]={2,3,5,7,13,17,19,31,61}; bool solve() { for(int i=0;i<9;i++) if(p==Mp[i]) return true; return false; } int main() { // freopen("input.txt","r",stdin); int T;cin>>T; while(T--){ cin>>p; if(solve()) cout<<"yes"< 
              
             
            
          
        
        
       
       
      
      

附表:梅森素数表(1-47个)

序号

p

Mp=(2^p)-1

Mp的位数

发现时间

发现者

1

2

3

1

古代

古人

2

3

7

1

古代

古人

3

5

31

2

古代

古人

4

7

127

3

古代

古人

5

13

8191

4

1456年

无名氏

6

17

131071

6

1588年

Cataldi

7

19

524287

6

1588年

Cataldi

8

31

2147483647

10

1772年

欧拉

9

61

2305843009213693951

19

1883年

Pervushin

10

89

618970019642690137449562111

27

1911年

Powers

11

107

162259276829213363391578010288127

33

1914年

Powers

12

127

170141183460469231731687303715884105727

39

1876年

卢卡斯

13

521

686479766013060971498190079908139321726

943530014330540939446345918554318339765

605212255964066145455497729631139148085

803712198799971664381257402829111505715

1

157

1952年1月30日

Robinson

14

607

531137992816767098689588206552468627329

593117727031923199444138200403559860852

242739162502265229285668889329486246501

015346579337652707239409519978766587351

943831270835393219031728127

183

1952年1月30日

Robinson

15

1279

104079321946643990819252403273640855386

152622472667048053191123504036080596733

602980122394417323241848424216139542810

077913835662483234649081399066056773207

629241295093892203457731833496615835504

729594205476898112116936771475484788669

625013844382602917323488853111608285384

165850282556046662248318909188018470682

222031405210266984354887329580288780508

69736186900714720710555703168729087

386

1952年6月25日

Robinson

16

2203

147597991521418023508489862273738173631

206614533316977514777121647857029787807

894937740733704938928938274850753149648

047728126483876025919181446336533026954

049696120111343015690239609398909022625

932693502528140961498349938822283144859

860183431853623092377264139020949023183

644689960821079548296376309423663094541

083279376990539998245718632294472963641

889062337217172374210563644036821845964

963294853869690587265048691443463745750

728044182367681351785209934866084717257

940842231667809767022401199028017047489

448742692474210882353680848507250224051

945258754287534997655857267022963396257

521263747789778550155264652260998886991

401354048380986568125041949768669777100

7

664

1952年10月7日

Robinson

17

2281

446087557183758429571151706402101809886

208632412859901111991219963404685792820

473369112545269003989026153245931124316

702395758705693679364790903497461147071

065254193353938124978226307947312410798

874869040070279328428810311754844108094

878252494866760969586998128982645877596

028979171536962503068429617331702184750

324583009171832104916050157628886606372

145501702225925125224076829605427173573

964812995250569412480720738476855293681

666712844831190877620606786663862190240

118570736831901886479225810414714078935

386562497968178729127629594924411960961

386713946279899275006954917139758796061

223803393537381034666494402951052059047

968693255388647930440925104186817009640

171764133172418132836351

687

1952年10月9日

Robinson

18

3217

259117086013202627776246767922441530941

818887553125427303974923161874019266586

362086201209516800483406550695241733194

177441689509238807017410377709597512042

313066624082916353517952311186154862265

604547691127595848775610568757931191017

711408826252153849035830401185072116424

747461823031471398340229288074545677907

941037288235820705892351068433882986888

616658650280927692080339605869308790500

409503709875902119018371991620994002568

935113136548829739112656797303241986517

250116412703509705427773477972349821676

443446668383119322540099648994051790241

624056519054483690809616061625743042361

721863339415852426431208737266591962061

753535748892894599629195183082621860853

400937932839420261866586142503251450773

096274235376822938649407127700846077124

2118230808041392980870575047138252645714

4837937112503208182612656664908425169945

3951887789613650248405739378594599444335

2311882801236604062624686092121503499375

8478229223714433962885848593821573882123

2393687046160677362909315071

969

1957年9月8日

Riesel

19

4253

1907970075244390738074680429695291736693

5699474994017739474188267352897978700505

3706368049835514900244303495954950709725

7621863112241488288119202169045422069607

4466616936422119528953843684539025016866

3932838805192055137154390912666527533007

3092926875390922570433625178573666246999

7540237546295449029325923330313733064353

1556539739921926201438606439020075174723

0290568382725050515719675946083500634044

9597766065626902082396082556701234418990

8927956646011998057988548630107637380993

5198265823897818881357054086530452196558

0175808125116408055460905746802820330871

8724654081055323215860189611391296030471

1084431467456719677663089258585472715073

1156376517100831824864711009761489031356

2856541784154881743146033909602737947385

0553559603318556145409000814563786590683

7031726769698000118775099549109035010841

7050917991562167972281070161305972518044

8720483313063837150948549384157385498946

0607072258473797817668642213435452698944

3028353644037187375385397838259511833166

4161343236956603676768977222879187734209

6898232608902615003151542416546211133752

7431154890666327374921446276833564519776

7976338755035486650939145564820314822488

8312702377703966770797655985733335701372

7342079099064400455741830654320379350833

2362458193488240647835856929248810219783

3297494990612266442137603468781535048499

1

1,281

1961年11月3日

Hurwitz

20

4423

2855425422282796139015635661021640083261

6423864470288919924745660228440039060065

3875954571505539843239754513915896150297

8783993770560714351697472211079887911982

0098847753133921428277201605900990458668

6254989084815735422480409022344297588352

5260043838906326161240763173874168811485

9248618836187390417578314569601691957439

0765598280188599035578448591077683677175

5204340742877265780062667596159707595213

2782855566278167838569158184443644481251

1562428136742490459363212810180276096088

1114010033775703635457251209240736469215

7679714619938761929656030268026179011813

2925012323046444438622308877924609373773

0124816816724244936744744885377701557830

0688085264816151306714481479028836666406

2257274665275787127374649231096375001170

9018907862633246195787957314256938050730

5611967758033808433338198750090296883193

5913095269821311141322393356490178488728

9822881562826008138312961436638459454311

4404375382154287127774560644785856415921

3328443580206422714694913091762716447041

6896780700967735904298089096167504529272

5800084350034483162829708990272864998199

4387647234574276263729694848304750917174

1861811306885187927486226122933413689280

5663438446664632657247616727566083910565

0528975713899320211121495795311427946254

5533053870678210676017687509778661004600

1460213840844802122505368905479374200309

5722096732954750721718115531871310231057

902608580607

1,332

1961年11月3日

Hurwitz

21

9689

478220278…225754111

2,917

1963年5月11日

Gillies

22

9941

346088282…789463551

2,993

1963年5月16日

Gillies

23

11213

281411201…696392191

3,376

1963年6月2日

Gillies

24

19937

431542479…968041471

6,002

1971年3月4日

布莱恩特·塔克曼

25

21701

448679166…511882751

6,533

1978年10月30日

Noll& Nickel

26

23209

402874115…779264511

6,987

1979年2月9日

Noll

27

44497

854509824…011228671

13,395

1979年4月8日

Nelson& Slowinski

28

86243

536927995…433438207

25,962

1982年9月25日

Slowinski

29

110503

521928313…465515007

33,265

1988年1月28日

Colquitt& Welsh

30

132049

512740276…730061311

39,751

1983年9月20日

Slowinski

31

216091

746093103…815528447

65,050

1985年9月6日

Slowinski

32

756839

174135906…544677887

227,832

1992年2月19日

Slowinski& Gage

33

859433

129498125…500142591

258,716

1994年1月10日

Slowinski& Gage

34

1257787

412245773…089366527

378,632

1996年9月3日

Slowinski& Gage

35

1398269

814717564…451315711

420,921

1996年11月13日

GIMPS/Joel Armengaud

36

2976221

623340076…729201151

895,932

1997年8月24日

GIMPS/Gordon Spence

37

3021377

127411683…024694271

909,526

1998年1月27日

GIMPS/Roland Clarkson

38

6972593

437075744…924193791

2,098,960

1999年6月1日

GIMPS/Nayan Hajratwala

39

13466917

924947738…256259071

4,053,946

2001年11月14日

GIMPS/Michael Cameron

40

20996011

125976895…855682047

6,320,430

2003年11月17日

GIMPS/Michael Shafer

41

24036583

299410429…733969407

7,235,733

2004年5月15日

GIMPS/Josh Findley

42*

25964951

122164630…577077247

7,816,230

2005年2月18日

GIMPS/Martin Nowak

43*

30402457

315416475…652943871

9,152,052

2005年12月15日

GIMPS/Curtis Cooper及Steven Boone

44*

32582657

124575026…053967871

9,808,358

2006年9月4日

GIMPS/Curtis Cooper及Steven Boone

45*

37156667

202254406…308220927

11,185,272

2008年9月6日

GIMPS/Hans-Michael Elvenich

46*

42643801

169873516…562314751

12,837,064

2009年4月12日

GIMPS/Odd M. Strindmo

47*

43112609

316470269…697152511

12,978,189

2008年8月23日

GIMPS/Edson Smith



(2)卢卡斯-莱默判定法

#include 
       
       
        
        
#include 
        
        
         
         
#include 
         
         
          
          
#include 
          
          
#include 
           
           
             #include 
            
              #include 
             
               using namespace std; const int maxn=50000+10; long long r[100],p; long long multi(long long a,long long b,long long mod)//a * b % mod 乘法换加法 { long long ret=0; while(b){ if(b&1) ret=(ret+a)%mod; b>>=1; a=(a<<1)%mod; } return ret; } int main() { // freopen("input.txt","r",stdin); int T;cin>>T; while(T--){ cin>>p; long long mod=((long long)1< 
               
              
             
           
         
         
        
        
       
       

(三)同余问题

1.扩展欧几里得求解线性同余方程(不定方程)

青蛙的约会题解:

假设走了t次相遇,则有等式(x+mt)-(y+nt)=pL成立,等价于求解同余方程(n-m)t≡(x-y) (mod L)的最小整数解

(a)对于一般同余方程ax=d mod b,方程有解,则有(a,d)| b ,所以问题第一步判断解的情况

(b)有(n-m)t+pL=x-y,t、p均为未知变量,将问题转化为求解ax+by=d的最小整数x,扩展欧几里得算法:

briefly:扩展欧几里得算法是辗转相除法求gcd的拓展,表现在ax+by=gcd(a,b),函数extended_gcd()不仅能返回gcd(a,b),还能求出gcd的线性系数x,y,具体的操作步骤如下:

 ①首先化简 ,得到新的ax+by=d,注意此时(a,b)=1

 ②先求ax+by=1的解x0、y0(解具有唯一性),利用扩展欧几里得算法得到唯一解x0,则ax+by=d的解x=d*x0

 ③通解X=x+b*k(k为整数)

(c)通过(b)实际上可以得到同余方程的通解,但是题目要求最小整数解,利用min=(X%b+b)%b,X取正取负均满足最小,问题得解

以CX=B-A(mod M)为例:

#include 
        
        
         
         
#include 
         
         
          
          
#include 
          
          
           
           
#include 
           
           
#include 
            
            
              #include 
             
               #include 
              
                using namespace std; typedef long long ll; const int maxn=1000000+10; ll x,y; ll extended_gcd(ll a,ll b,ll &x,ll &y)//扩展欧几里得算法求ax+by=gcd(a,b)的线性系数x,y,返回gcd(a,b) { if(b==0) {x=1;y=0;return a;} ll d=extended_gcd(b,a%b,y,x); y-=a/b*x; return d; } int main() { // freopen("input.txt","r",stdin); ll a,b,m,A,B,C,k; while(cin>>A>>B>>C>>k&&(A||B||C||k)){ a=C;b=(ll)1< 
                
               
              
            
          
          
         
         
        
        

2.一元线性同余方程组+中国剩余定理

(1)一元线性同余方程

/**********************一般线性同余方程组求解思路***********************/

X mod r1=a1
X mod r2=a2
...
...
...
X mod rn=an

首先,我们看两个式子的情况
X mod a1=r1……………………………………………………………(1)
X mod a2=r2……………………………………………………………(2)
则有 
X=a1*y1+r1………………………………………………………………(*)
X=a2*y2+r2
那么 a1*y1+r1=a2*y2+r2
整理,得
a1*y1-a2*y2=r2-r1
令(a,b,x,y,m)=(m1,m2,k1,k2,r2-r1),原式变成
ax+by=m            (a=a1,b=a2,m=r2-r1)
熟悉吧?


对于每一个方程GCD(1,ai) | ri=1|ri=0,方程都有解无需验证,只需验证联立后的方程是否有解; 
此时,因为GCD(a,b)=1不一定成立,GCD(a,b) | m 也就不一定成立。所以应该先判 若 GCD(a,b) | m 不成立,则!!!方程无解!!!。
否则,继续往下。

解出(x,y),将y1=x反代回(*),得到X。
于是X就是这两个方程的一个特解,通解就是 X'=X+k*LCM(m1,m2)                          //可以分别从方程(1)(2)的通解形式想到
这个式子再一变形,得 X' mod LCM(m1,m2)=X
这个方程一出来,说明我们实现了(1)(2)两个方程的合并。
令 M=LCM(m1,m2),R=特解X
就可将合并后的方程记为 X mod M = R。

然后,扩展到n个方程。
用合并后的方程再来和其他的方程按这样的方式进行合并,最后就能只剩下一个方程 X mod M=R,其中 M=LCM(m1,m2,...,mn)。
那么,X便是原模线性方程组的一个特解,通解为 X'=X+k*M。

如果,要得到X的最小正整数解,就还是原来那个方法:

min=(x%t+t)%t;

……………………………………详见代码

#include 
         
         
          
          
#include 
          
          
           
           
#include 
           
           
            
            
#include 
            
            
#include 
             
             
               #include 
              
                #include 
               
                 using namespace std; const int maxn=1000000+10; long long a1,a2,r1,r2,x,y; int n; long long extended_gcd(long long a,long long b,long long &x,long long &y)//扩展欧几里得算法:求等式ax+by=gcd(a,b)中的x,y;返回d=gcd(a,b) { if(b==0) {x=1;y=0;return a;} long long d=extended_gcd(b,a%b,y,x); y-=a/b*x; return d; } long long solve() { cin>>a1>>r1; bool ok=true; while(--n){ cin>>a2>>r2; long long a=a1,b=a2,m=r2-r1; long long d=extended_gcd(a,b,x,y); //求出线性系数 x 和 gcd(a,b) if(m%d) ok=false; //存在一组方程无解就标记,注意不能return ,否则数据没有读完就输出了,WA x=((x*m/d)%(b/d)+(b/d))%(b/d); //求ax+by=m的最小正整数解,注意从扩展欧几里得算法处理解 r1=x*a1+r1; //r1即为方程的一个特解 a1=(a1*a2)/d; //a1=lcm(a1,a2) } if(ok) return r1; else return -1; } int main() { // freopen("input.txt","r",stdin); while(cin>>n){ cout< 
                
                  < 
                  
                 
                
               
             
           
           
          
          
         
         

(2)中国剩余定理


ll China()
{
   ll M1,ans=0;
   M=1;
   for(int i=1;i<=3;i++) M*=m[i];
   for(int i=1;i<=3;i++){
    M1=M/m[i];
    t=extended_gcd(M1,m[i],x,y);
    ans=(ans+M1*x*a[i])%M;
   }
   if(ans<0) ans+=M;
   return ans;
}

3.高次同余方程(Baby Step Giant Step 算法)


#include 
          
          
           
           
#include 
           
           
            
            
#include 
            
            
             
             
#include 
             
             
#include 
              
              
                #include 
               
                 #include 
                
                  using namespace std; typedef long long ll; const int maxn = 65535; struct hash{ int a,b,next; }Hash[maxn << 1]; int flg[maxn + 66]; int top,idx; void ins(int a,int b) { int k = b & maxn; if(flg[k] != idx){ flg[k] = idx; Hash[k].next = -1; Hash[k].a = a; Hash[k].b = b; return ; } while(Hash[k].next != -1){ if(Hash[k].b == b) return ; k = Hash[k].next; } Hash[k].next = ++ top; Hash[top].next = -1; Hash[top].a = a; Hash[top].b = b; } int find(int b) { int k = b & maxn; if(flg[k] != idx) return -1; while(k != -1){ if(Hash[k].b == b) return Hash[k].a; k = Hash[k].next; } return -1; } int gcd(int a,int b){return b?gcd(b,a%b):a;} int extended_gcd(int a,int b,int& x,int& y) { if (b==0){x=1,y=0;return a;} int d=extended_gcd(b,a%b,y,x); y-=a/b*x; return d; } int Inval(int a,int b,int n){ int x,y,e; extended_gcd(a,n,x,y); e=(ll)x*b%n; return e<0?e+n:e; } int quickpow_mod(ll a,int b,int c) { ll ret=1%c;a%=c; while(b){if(b&1)ret=ret*a%c;a=a*a%c;b>>=1;} return ret; } int BabyStep(int A,int B,int C) { top = maxn; ++ idx; ll buf=1%C,D=buf,K; int i=0,d=0,tmp; for(i=0;i<=100;buf=buf*A%C,++i)if(buf==B)return i; while((tmp=gcd(A,C))!=1){ if(B%tmp)return -1; ++d; C/=tmp; B/=tmp; D=D*A/tmp%C; } int M=(int)ceil(sqrt((double)C)); for(buf=1%C,i=0;i<=M;buf=buf*A%C,++i)ins(i,buf); for(i=0,K=quickpow_mod((ll)A,M,C);i<=M;D=D*K%C,++i){ tmp=Inval((int)D,B,C);int w ; if(tmp>=0&&(w = find(tmp)) != -1) return i*M+w+d; } return -1; } int main() { //freopen("input.txt","r",stdin); int A,B,C; while(cin>>A>>C>>B&&(A || B || C)){ B %= C; int tmp=BabyStep(A,B,C); if(tmp<0)puts("No Solution"); else cout< 
                 
                   < 
                   
                  
                 
                
              
            
            
           
           
          
          

4.整数快速幂+矩阵快速幂

(1)整数快速幂

ll quickpow_mod(ll a,ll b)
{
    ll ans=1;
    while(b){
        if(b&1) ans=(ans*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return ans;
}

(2)矩阵快速幂


#include 
           
           
            
            
#include 
            
            
             
             
#include 
             
             
              
              
#include 
              
              
#include 
               
               
                 #include 
                
                  #include 
                 
                   using namespace std; typedef long long ll; const int maxn = 50; const int mod=10000; ll n; struct matrix { ll m[2][2]; }a,p; matrix multi(matrix a,matrix b) { matrix c; for(int i=0;i<2;i++) for(int j=0;j<2;j++){ c.m[i][j]=0; for(int k=0;k<2;k++) c.m[i][j]+=a.m[i][k]*b.m[k][j]; c.m[i][j]%=mod; } return c; } matrix quickpow_mod(matrix a,ll b) { matrix ans=p; while(b){ if(b&1) ans=multi(ans,a); b>>=1; a=multi(a,a); } return ans; } int main() { // freopen("input.txt","r",stdin); a.m[0][0]=a.m[0][1]=a.m[1][0]=1;a.m[1][1]=0;//a、p矩阵初始化 p.m[0][0]=p.m[1][1]=1;p.m[0][1]=p.m[1][0]=0; matrix ans; while(cin>>n&&n!=-1){ ans=quickpow_mod(a,n); cout< 
                  
                    < 
                    
                   
                  
                 
               
             
             
            
            
           
           

5.特殊不定方程:毕达哥拉斯三元组+佩尔方程



(四)乘性函数问题

1.欧拉函数


(一)直接实现:直接套用定理求解欧拉函数值

ll phi(ll n)
{
    ll res=n;
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            res=res-res/i;
            do{
                n/=i;
            }while(n%i==0);
        }
    }
    if(n>1) res=res-res/n;
    return res;
}
(二)递推求欧拉函数:欧拉函数值打表

void init()
{
   for(int i=1;i<=maxn;i++)  phi[i]=i;
   for(int i=2;i<=maxn;i+=2) phi[i]/=2;
   for(int i=3;i<=maxn;i+=2)
     if(phi[i]==i){
     for(int j=i;j<=maxn;j+=i)
        phi[j]=phi[j]/i*(i-1);
   }
}

2.因子和与因子个数


(1)正因子个数

ll count(ll n)
{
    ll ans=1;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            ll a=0;
            do{
                n/=i;
                a++;
            }while(n%i==0);
            ans=ans*(a+1);
        }
    }
    if(n>1) ans=ans*2;
    return ans;
}

(2)正因子之和

ll sum(ll n)
{
    ll ans=1;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            ll a=1;
            do{
                n/=i;
                a*=i;
            }while(n%i==0);
            ans=ans*(a*i-1)/(i-1);
        }
    }
    if(n>1) ans*=(n+1);
    return ans;
}

3.完全数

完全数,又称完美数或完备数,是一些特殊的自然数,它所有的真因子(即除了自身以外的约数)之和,恰好等于它本身。

或者可以理解为,如果n是一个正整数,且所有正因子之和等于2n,那么n称为完全数。

完全数有6个重要性质:

性质1 完全数都能写成连续自然数之和;

性质2 每个完全数的全部因数倒数之和都是2,因此每个完全数都是调和数;

性质3 除了6以外的完全数,每个数都可以写成连续奇数的立方和;

性质4 每个完全数都可以表达成2的一些连续正整数次幂之和;

性质5 完全数都是以6或8结尾;

性质6 位数字相加直到变成个位数,这个个位数一定是1.

附表:前12个完美数(目前共发现48个)

个数

完全数

1

6

2

28

3

496

4

8128

5

33550336

6

8,589,869,056

7

137,438,691,328

8

2,305,843,008,139,952,128

9

2,658,455,991,569,831,744,654,692,615,953,842,176

10

191,561,942,608,236,107,294,793,378,084,303,638,130,997,321,548,169,216

11

13,164,036,458,569,648,337,239,753,460,458,722,910,223,472,318,386,943,117,783,728,128

12

14,474,011,154,664,524,427,946,373,126,085,988,481,573,677,491,474,835,889,066,354,349,131,199,152,128



4.莫比乌斯反演


int mobi(int n)
{
    int ans=1;
    for(int i=2;i*i<=n;i++)
    if(n%i==0){
        ans*=-1;
        int k=0;
        do{
            k++;
            if(k>1) return 0;
            n/=i;
        }while(n%i==0);
    }
    if(n>1) ans*=-1;
    return ans;
}




  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
数论基础及其应用 作者:沈忠华 编著 出版时间:2015年版 内容简介   《数论基础及其应用》为数学与密码学交叉学科的特色教材,内容包括整除理论、同余、连分数、同余方程、原根。《数论基础及其应用》以数论知识为主线,有机地融入数论应用(主要是在密码学中的应用)的内容,理论与应用的知识的广度和深度都适度。《数论基础及其应用》可作为数学与应用数学专业、信息与计算科学专业和信息安全专业的本科生基础教材,也可作为密码学与信息安全专业的研究生教材。 目录 前言 第1章整除理论 1.1带余数除法 1.2辗转相除法 1.3最大公约数的性质 1.4最小公倍数 1.5算术基本定理 第2章同余 2.1同余的基本性质 2.2计算星期几 2.3循环比赛 第3章简单密码 3.1仿射加密 3.2矩阵加密 第4章剩余系 4.1完全剩余系 4.2简化剩余系 4.3Euler定理,Fermat定理 4.4数论函数 第5章不定方程 5.1一次不定方程 5.2方程x2+y2=x2 第6章同余方程 6.1同余方程的基本概念 6.2孙子定理 6.3模ρα的同余方程 6.4素数模的同余方程 第7章公钥密码 7.1公钥密码系统 7.2RSA加密 第8章二次剩余 8.1素数模的二次同余方程 8.2Legendre符号,二次互反律 8.3Jacobi符号 第9章原根 9.1指数及其基本性质 9.2原根与指标 9.3伪素数 第10章实数的表示 10.1连分数的基本性质 10.2实数的连分数表示 10.3循环连分数 10.4实数的b进制表示 第11章平方和 11.1二平方之和 11.2四平方之和 附录

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值