HDU 4746 Mophues 莫比乌斯反演

分析:

http://blog.csdn.net/acdreamers/article/details/12871643

分析参见这一篇

http://wenku.baidu.com/view/fbe263d384254b35eefd34eb.html

分块看这一篇

#include<cstdio>
#include<cstring>
#include<queue>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
typedef long long LL;
const int N=5e5+5;
const int INF=0x3f3f3f3f;
bool vis[N];
int prime[N],mu[N];
void getmu()
{
    mu[1] = 1;
    int cnt = 0;
    for(int i=2; i<=N-5; i++)
    {
        if(!vis[i])
        {
            prime[cnt++] = i;
            mu[i] = -1;
        }
        for(int j=0; j<cnt&&i*prime[j]<=N-5; j++)
        {
            vis[i*prime[j]] = 1;
            if(i%prime[j]) mu[i*prime[j]] = -mu[i];
            else
            {
                mu[i*prime[j]] = 0;
                break;
            }
        }
    }
}
int cal(int n,int x){
    int res=0;
    do{
       ++res;
       n/=x;
    }while(n%x==0);
    return res;
}
int num[N];
int F[N][20],T,n,m,p;
int main(){
    getmu();
    for(int i=2;i<=N-5;++i)
     if(!num[i])
        for(int j=i;j<=N-5;j+=i)
           num[j]+=cal(j,i);

    for(int i=1;i<=N-5;++i)
      for(int j=i;j<=N-5;j+=i)
        F[j][num[i]]+=mu[j/i];

    for(int i=1;i<=N-5;++i)
       for(int j=1;j<19;++j)
       F[i][j]+=F[i][j-1];

    for(int i=1;i<=N-5;++i)
     for(int j=0;j<19;++j)
      F[i][j]+=F[i-1][j];

    scanf("%d",&T);
    while(T--){
     scanf("%d%d%d",&n,&m,&p);
     LL ans=0;
     if(p>=19){
        printf("%I64d\n",1ll*n*m);
        continue;
     }
     if(n>m)swap(n,m);
     for(int i=1,j;i<=n;i=j+1){
        j=min(n/(n/i),m/(m/i));
        ans+=(1ll*F[j][p]-F[i-1][p])*(n/i)*(m/i);
     }
     printf("%I64d\n",ans);
    }
    return 0;
}

时间: 2024-10-13 15:15:32

HDU 4746 Mophues 莫比乌斯反演的相关文章

HDU 4746 Mophues (莫比乌斯反演应用)

Mophues Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 327670/327670 K (Java/Others) Total Submission(s): 980    Accepted Submission(s): 376 Problem Description As we know, any positive integer C ( C >= 2 ) can be written as the multiply of

HDU 4746 Mophues 莫比乌斯第三弹

题意:1<=x<=n,1<=y<=m,使得gcd(x,y)=k,k的素因数个数小于等于p 例:24=2*2*2*3,k=4 解:设f[n]为gcd(a,b)=n的对数 F[d]为d|gcd(a,b)的对数 f[n]=sigema(mu[i],F[i*n]): f[1]=mu[1]*F[1]+mu[2]*F[1*2]+...+mu[n]*F[1*n] f[2]=mu[2]*F[2]+mu[2]*F[2*2]+...+mu[n]*F[2*n] ...... sum=f[1]+f[2]+

HDU - 4746预处理莫比乌斯反演

链接 求[1,n] 和 [1,m]中有多少对数的GCD的素因子个数小于等于p 直接暴力做特定超时,所以我们想办法预处理,对于p大于18(1到5e5的最大素数因子个数)的情况,每一对都满足条件,O(1)得结果. p<=18时,预处理sum[i][j]sum[i][j]表示所有能整除i的质因子个数<=j的(x,y)的对数,然后求一个前缀和,ans=∑⌊n/d⌋∗⌊m/d⌋∗∑k|dμ(d/k) //#pragma comment(linker, "/stack:200000000&quo

HDU - 6715 - 算术 = 莫比乌斯反演

http://acm.hdu.edu.cn/showproblem.php?pid=6715 题意: 求:\(\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{m}\mu(lcm(i,j))\),其中n,m是1e6范围内,10组. 不会,想了很久,也不知道假在哪里.大概是一开始方向就错了. 正解: 所求:\(\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{m}\mu(lcm(i,j))\) 即:\(\sum\limits_{i=1}^

hdu.5212.Code(莫比乌斯反演 &amp;&amp; 线性筛)

Code Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 300    Accepted Submission(s): 124 Problem Description WLD likes playing with codes.One day he is writing a function.Howerver,his computer b

【莫比乌斯】HDU 4746 Mophues

通道:http://acm.hdu.edu.cn/showproblem.php?pid=4746 题意:定义f(x) = x分解质因数出来的因子个数,如 x = p0 * p0 * p0 * p1 * p2,则f(x) = 5,特殊的, f(1) = 0,求 i = [1..n], j = [1..m] 组成的n*m组(i, j)对中,有多少组f( gcd(i,j) ) <= p 思路: 代码: TAG:

HDU4746 Mophues(莫比乌斯反演)

Mophues Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 327670/327670 K (Java/Others) Total Submission(s): 647    Accepted Submission(s): 263 Problem Description As we know, any positive integer C ( C >= 2 ) can be written as the multiply of

HDU 5072 Coprime (莫比乌斯反演+容斥+同色三角形)

Coprime Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 1469    Accepted Submission(s): 579 Problem Description There are n people standing in a line. Each of them has a unique id number. Now

[HDU 5072] Coprime 莫比乌斯反演

题意 ? 给定一个长度为 $n$ 的序列 $A = \left\{ a_1, a_2, ..., a_n \right\}$ . ? 问有多少个三元组 $(i, j, k)(i \ne j, i \ne k, j \ne k)$ , 满足 $\left\{ \begin{aligned} & a_i \perp a_j \\ & a_i \perp a_k \\ & a_j \perp a_k \end{aligned} \right.$ 或 $\left\{ \begin{ali