zoukankan      html  css  js  c++  java
  • 求欧拉函数

    procedure euler;
     var
      i,j:longint;
       begin
         phi[1]:=1;
         for i:=2 to n do
           begin
             if not mark[i] then
               begin
                 inc(tot);
                 p[tot]:=i;
                 phi[i]:=i-1;
               end;
    
             for j:=1 to n do
               begin
                 if i*p[j]>n then break;
                 mark[i*p[j]]:=true;
                 if i mod p[j]=0 then
                   begin
                     phi[i*p[j]]:=phi[i]*p[j];
                     break;
                   end else phi[i*p[j]]:=phi[i]*(p[j]-1);
               end;
           end;
       end;

     c++

    void euler(){
           b[1]=1;phi[1]=1;
           for (LL i=2;i<=n;i++){
                if (b[i]==0) {ss[++cnt]=i;phi[i]=i-1;}
                
                for (LL j=1;j<=cnt;j++){
                      if (i*ss[j]>n) break;
                      b[i*ss[j]]=1;
                      if (i%ss[j]==0) {phi[i*ss[j]]=phi[i]*ss[j];break;}
                  else phi[i*ss[j]]=phi[i]*(ss[j]-1);
                }
           }
      } 
  • 相关阅读:
    列表方块与格式与布局
    框架与样式表的基本概念
    表单
    内容容器,常用标签
    CSS3
    表单验证
    练习题
    document对象
    windows对象
    函数
  • 原文地址:https://www.cnblogs.com/zhujiangning/p/5275897.html
Copyright © 2011-2022 走看看