bzoj3309 DZY Loves Math

题目描述:

bz

题解:

线性筛……

瞎jb反演得到$ans=\sum\limits _{T=1}^{a} \lfloor \frac{a}{T} \rfloor \lfloor \frac{b}{T} \rfloor \sum\limits _{d|T} f(d) \mu(\frac{T}{d})$。

后面那个要求$O(n)$筛出来。

剩下的我讲不明白,直接挂PoPoQQQ题解了。

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 10000050;
template<typename T>
inline void read(T&x)
{
    T f = 1,c = 0;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){c=c*10+ch-'0';ch=getchar();}
    x = f*c;
}
bool vis[N];
int pri[N/10],pnt,f[N],fk[N];
ll s[N];
inline void init()
{
    for(register int i=2;i<=10000000;++i)
    {
        if(!vis[i])
        {
            pri[++pnt]=i;
            s[i] = 1;
            f[i] = 1,fk[i] = i;
        }
        for(register int j=1;i*pri[j]<=10000000;++j)
        {
            int now = i*pri[j];
            vis[now]=1;
            if(i%pri[j])
            {
                f[now] = 1,fk[now] = pri[j];
                s[now] = (f[i]==1)?-s[i]:0;
            }else
            {
                f[now] = f[i]+1,fk[now] = fk[i]*pri[j];
                int las = i/fk[i];
                if(las==1)s[now]=1;
                else s[now]=(f[las]==f[now])?-s[las]:0;
                break;
            }
        }
    }
    for(register int i=1;i<=10000000;++i)s[i]+=s[i-1];
}
int T,n,m;
inline void work()
{
    read(n),read(m);
    ll ans = 0;int mn = min(n,m);
    for(register int i=1,j;i<=mn;i=j+1)
    {
        j = min(n/(n/i),m/(m/i));
        ans+=1ll*(n/i)*(m/i)*(s[j]-s[i-1]);
    }
    printf("%lld\n",ans);
}
int main()
{
//    freopen("tt.in","r",stdin);
    read(T);init();
    while(T--)work();
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/LiGuanlin1124/p/11149735.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值