zoukankan      html  css  js  c++  java
  • 三行写出莫比乌斯函数(HDU1695)

    莫比乌斯函数是可以在三行内写出来的

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 typedef long long ll;
     4 const int maxn=1000000;
     5 int mu[maxn+10],T;
     6 void Mobius(){
     7     for(int d=1,k;d<=maxn;++d)
     8         for(mu[1]=1,k=d<<1;k<=maxn;mu[k]=mu[k]-mu[d],k+=d);
     9     for(int i=1;i<=maxn;++i)mu[i]+=mu[i-1];
    10 }
    11 int main(){
    12     Mobius();
    13     ios::sync_with_stdio(false);
    14     cin>>T;
    15     for(int kase=1,a,b,c,d,k;kase<=T;++kase){
    16         cin>>a>>b>>c>>d>>k;
    17         if(!k){
    18             cout<<"Case "<<kase<<": 0"<<endl;
    19             continue;
    20         }
    21         b/=k;d/=k;
    22         if(b>d)b^=d^=b^=d;
    23         ll ans1=0,ans2=0;
    24         for(int i=1,t;i<=b;i=t+1){
    25             t=min(b/(b/i),d/(d/i));
    26             ans1+=1ll*(mu[t]-mu[i-1])*(b/i)*(d/i);
    27         }
    28         for(int i=1,t;i<=b;i=t+1){
    29             t=b/(b/i);
    30             ans2+=1ll*(mu[t]-mu[i-1])*(b/i)*(b/i);
    31         }
    32         ans1-=ans2/2;
    33         cout<<"Case "<<kase<<": "<<ans1<<endl;
    34     }
    35 }
  • 相关阅读:
    rh
    re模块
    粘包现象
    子类调用父类方法
    北大医院条码
    戴德金-连续性和无理数-第1页
    数学名词
    核心英语笔记,含记忆术mnemonics
    python笔记
    收集的句子
  • 原文地址:https://www.cnblogs.com/ndqzhang1111/p/7429709.html
Copyright © 2011-2022 走看看