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("\n");
40     printf("%lld\n",s*2+1);
41     return 0;
42 }
View Code

 

转载于:https://www.cnblogs.com/onlyRP/p/5176312.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值