【bzoj2671】Calc 莫比乌斯函数

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

题解
http://blog.csdn.net/FSAHFGSADHSAKNDAS/article/details/56499481

代码

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#define ll long long
#define mod 1000000007
#define N 50005
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
bool flag[N];
int tot,p[N],miu[N],n,m,pos;
ll ans;
void pre()
{
    miu[1]=1;
    for (int i=2;i<N;i++)
    {
        if (!flag[i]) p[++tot]=i,miu[i]=-1;
        for (int j=1;j<=tot&&p[j]*i<N;j++)
        {
            flag[i*p[j]]=1;
            if (i%p[j]==0) break;
            miu[i*p[j]]=-miu[i];
        }
    }
}
int main()
{
    pre();
    scanf("%d",&n);m=sqrt(n);
    for (int d=1;d<=m;d++)
    {
        for (int i=2;i<=m/d;i++)
        {
            int last=n/(d*d*i);
            for (int x=i+1,p=0;x<=2*i-1&&x<=last;x=pos+1)
            {
                pos=last/(last/x);
                ans+=1LL*miu[d]*(min(pos,2*i-1)-x+1)*(last/x);
            }
        }
    } 
    cout<<ans;
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值