• bzoj 2671 莫比乌斯反演


     Calc

    Time Limit: 10 Sec  Memory Limit: 128 MB
    Submit: 451  Solved: 234
    [Submit][Status][Discuss]

    Description

      给出N,统计满足下面条件的数对(a,b)的个数:
      1.1<=a<b<=N
      2.a+b整除a*b
     

    Input

     一行一个数N

     

    Output

     一行一个数表示答案

    Sample Input

    15

    Sample Output

    4

    HINT

    数据规模和约定

    Test N Test N 

    1 <=10 11 <=5*10^7 

    2 <=50 12 <=10^8 

    3 <=10^3 13 <=2*10^8 

    4 <=5*10^3 14 <=3*10^8 

    5 <=2*10^4 15 <=5*10^8 

    6 <=2*10^5 16 <=10^9 

    7 <=2*10^6 17 <=10^9 

    8 <=10^7 18 <=2^31-1 

    9 <=2*10^7 19 <=2^31-1 

    10 <=3*10^7 20 <=2^31-1


    Source

     
    [Submit][Status][Discuss]


    HOME Back

    http://blog.csdn.net/popoqqq/article/details/45095601

     1 #pragma GCC optimize(2)
     2 #pragma G++ optimize(2)
     3 #include<cstdio>
     4 #include<iostream>
     5 #include<cstring>
     6 #include<cmath>
     7 #define ll long long
     8 #define mod 1000000007
     9 #define N 50005
    10 using namespace std;
    11 inline int read()
    12 {
    13     int x=0,f=1;char ch=getchar();
    14     while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
    15     while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    16     return x*f;
    17 }
    18 
    19 bool flag[N];
    20 int tot,p[N],miu[N],n,m,pos;
    21 ll ans;
    22 
    23 void pre()
    24 {
    25     miu[1]=1;
    26     for (int i=2;i<N;i++)
    27     {
    28         if (!flag[i]) p[++tot]=i,miu[i]=-1;
    29         for (int j=1;j<=tot&&p[j]*i<N;j++)
    30         {
    31             flag[i*p[j]]=1;
    32             if (i%p[j]==0) break;
    33             miu[i*p[j]]=-miu[i];
    34         }
    35     }
    36 }
    37 int main()
    38 {
    39     pre();
    40     scanf("%d",&n);m=sqrt(n);
    41     for (int d=1;d<=m;d++)
    42     {
    43         for (int i=2;i<=m/d;i++)
    44         {
    45             int last=n/(d*d*i);
    46             for (int x=i+1,p=0;x<=2*i-1&&x<=last;x=pos+1)
    47             {
    48                 pos=last/(last/x);
    49                 ans+=1LL*miu[d]*(min(pos,2*i-1)-x+1)*(last/x);
    50             }
    51         }
    52     } 
    53     printf("%lld",ans);
    54 }
  • 相关阅读:
    c# ThreadPool 判断子线程全部执行完毕的四种方法
    很多人都爱玩的lol..
    Go 的位操作
    wrk压测工具
    Go函数作为值与类型
    家用PC发展设想
    开车的烦恼
    一款一体机的设想
    nodejs开发环境的搭建
    Python网页抓取程序(续)
  • 原文地址:https://www.cnblogs.com/fengzhiyuan/p/8530705.html
Copyright © 2020-2023  润新知