zoukankan      html  css  js  c++  java
  • bzoj 2190

    开始补我不敢碰的数论QAQ

    看了资料感觉还是很晕,先把结论记下吧。。

    若(x,y)符合提议gcd(x-1,y-1)=1,那么先欧拉筛法求出s=sigma(phi[i]),然后注意(1,2)(2,1)(2,2)3个点,答案就是2*s+1了

     1 #include<bits/stdc++.h>
     2 #define inc(i,l,r) for(int i=l;i<=r;i++)
     3 #define dec(i,l,r) for(int i=l;i>=r;i--)
     4 #define link(x) for(edge *j=h[x];j;j=j->next)
     5 #define mem(a) memset(a,0,sizeof(a))
     6 #define inf 1e9
     7 #define ll long long
     8 #define succ(x) (1<<x)
     9 #define NM 40000+5
    10 using namespace std;
    11 int read(){
    12     int x=0,f=1;char ch=getchar();
    13     while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    14     while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    15     return x*f;
    16 }
    17 int phi[NM],p[NM],n,tot,check[NM];
    18 ll s;
    19 int main(){
    20     freopen("data.in","r",stdin);
    21     n=read();
    22     s=phi[1]=1;
    23     inc(i,2,n-1){
    24         if(!check[i]){
    25             p[++tot]=i;
    26             phi[i]=i-1;
    27         }
    28         s+=phi[i];
    29         inc(j,1,tot){
    30             if(i*p[j]>n)break;
    31             check[i*p[j]]++;
    32             if(i%p[j])phi[i*p[j]]=phi[i]*phi[p[j]];
    33             else{
    34                 phi[i*p[j]]=phi[i]*p[j];
    35                 break;
    36             }
    37         }
    38     }
    39 //    inc(i,1,n)printf("%d ",phi[i]);printf("
    ");
    40     printf("%lld
    ",s*2+1);
    41     return 0;
    42 }
    View Code
  • 相关阅读:
    scss的初级学习随笔小计
    trimpash实现jd选项卡首次输入
    透明度动画
    js原生动画一匀速动画
    filter滤镜的使用
    scss实现不同方向的三角
    模板方法模式-考题抄错,会做也白搭
    设计模式概述
    mysql数据库
    夜饮东坡醒复醉
  • 原文地址:https://www.cnblogs.com/onlyRP/p/5176312.html
Copyright © 2011-2022 走看看