Mophues

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 327670/327670 K (Java/Others)
Total Submission(s): 579    Accepted Submission(s): 235

Problem Description
As we know, any positive integer C ( C >= 2 ) can be written as the multiply of some prime numbers:
    C = p1×p2× p3× ... × pk
which p1, p2 ... pk are all prime numbers.For example, if C = 24, then:
    24 = 2 × 2 × 2 × 3
    here, p1 = p2 = p3 = 2, p4 = 3, k = 4

Given two integers P and C. if k<=P( k is the number of C's prime factors), we call C a lucky number of P.

Now, XXX needs to count the number of pairs (a, b), which 1<=a<=n , 1<=b<=m, and gcd(a,b) is a lucky number of a given P ( "gcd" means "greatest common divisor").

Please note that we define 1 as lucky number of any non-negative integers because 1 has no prime factor.

 
Input
The first line of input is an integer Q meaning that there are Q test cases.
Then Q lines follow, each line is a test case and each test case contains three non-negative numbers: n, m and P (n, m, P <= 5×105. Q <=5000).
 
Output
For each test case, print the number of pairs (a, b), which 1<=a<=n , 1<=b<=m, and gcd(a,b) is a lucky number of P.
 
Sample Input
2
10 10 0
10 10 1
 
Sample Output
63
93
 
Source
 
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std; typedef __int64 LL;
const int maxn=*1e5+;
int prime[maxn],mu[maxn],num,cnt[maxn],mbs[maxn][];
bool flag[maxn];
void swap(int &a,int &b){ int t=a;a=b;b=t;}
int min(int a,int b){return a<b?a:b;} void init()
{
int i,j;
mu[]=;cnt[]=;
memset(flag,true,sizeof(flag));
for(i=;i<maxn;i++)
{
if(flag[i])
{
prime[num++]=i;mu[i]=-;cnt[i]=;
}
for(j=;j<num&&i*prime[j]<maxn;j++)
{
flag[i*prime[j]]=false;
cnt[i*prime[j]]=cnt[i]+;
if(i%prime[j]==)
{
mu[i*prime[j]]=;break;
}
else mu[i*prime[j]]=-mu[i];
}
}
memset(mbs,,sizeof(mbs));
for(i=;i<maxn;i++)//求出单项的mbs[i][j],表示的是i为公因子时的情况。
for(j=i;j<maxn;j+=i)
mbs[j][cnt[i]]+=mu[j/i];
for(i=;i<maxn;i++) //以下是求前缀和
for(j=;j<;j++)
mbs[i][j]+=mbs[i-][j];
for(i=;i<maxn;i++)
for(j=;j<;j ++)
mbs[i][j]+=mbs[i][j-];
} int main()
{
num=;
init();
int i,j,t,n,m,p;
scanf("%d",&t);
while(t--)
{
scanf("%d %d %d",&n,&m,&p);
if(p>=){ printf("%I64d\n",(LL)n*m);continue;}
if(n>m) swap(n,m);
LL ans=;
for(i=,j=;i<n;i=j+)
{
j=min(n/(n/i),m/(m/i));
ans+=(LL)(mbs[j][p]-mbs[i-][p])*(n/i)*(m/i);
}
printf("%I64d\n",ans);
}
return ;
}

hud 4746 莫比乌斯反演的更多相关文章

  1. HDU 4746 (莫比乌斯反演) Mophues

    这道题看巨巨的题解看了好久,好久.. 本文转自hdu4746(莫比乌斯反演) 题意:给出n, m, p,求有多少对a, b满足gcd(a, b)的素因子个数<=p,(其中1<=a<= ...

  2. HDU 4746 莫比乌斯反演+离线查询+树状数组

    题目大意: 一个数字组成一堆素因子的乘积,如果一个数字的素因子个数(同样的素因子也要多次计数)小于等于P,那么就称这个数是P的幸运数 多次询问1<=x<=n,1<=y<=m,P ...

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

    Mophues Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 327670/327670 K (Java/Others) Total ...

  4. HDU 4746 Mophues【莫比乌斯反演】

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4746 题意: 1≤x,y≤n , 求gcd(x,y)分解后质因数个数小于等k的(x,y)的对数. 分 ...

  5. Mophues HDU - 4746 (莫比乌斯反演)

    Mophues \[ Time Limit: 10000 ms\quad Memory Limit: 262144 kB \] 题意 求出满足 \(gcd\left(a,b\right) = k\), ...

  6. HDU 4746 Mophues(莫比乌斯反演)题解

    题意: \(Q\leq5000\)次询问,每次问你有多少对\((x,y)\)满足\(x\in[1,n],y\in[1,m]\)且\(gcd(x,y)\)的质因数分解个数小于等于\(p\).\(n,m, ...

  7. hdu1695 GCD(莫比乌斯反演)

    题意:求(1,b)区间和(1,d)区间里面gcd(x, y) = k的数的对数(1<=x<=b , 1<= y <= d). 知识点: 莫比乌斯反演/*12*/ 线性筛求莫比乌 ...

  8. BZOJ 2154: Crash的数字表格 [莫比乌斯反演]

    2154: Crash的数字表格 Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 2924  Solved: 1091[Submit][Status][ ...

  9. BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 4032  Solved: 1817[Submit] ...

随机推荐

  1. no pointer in java

    Why there are no pointers in Java? In Java there are references instead of pointers. These reference ...

  2. Launch Instance---source for openstack

    If you want to create an instance that uses ephemeral storage, meaning the instance data is lost whe ...

  3. Android layout的XML

    [注]此文是在学习andriod中的一些理解和总结,若有错望留言指教,谢谢 1 <RelativeLayout xmlns:android="http://schemas.androi ...

  4. oracle系統表、數據字典介紹與日常問題診斷

    oracle系統表.數據字典介紹與日常問題診斷 數據字典是由唯讀的table和view組成的,產生於$oracle_home\rdbms\admin\catalog.sql.裡面儲存Oracle資料庫 ...

  5. c++IDE

    暂时使用Code::Blocks 16.01. 因为之前没有c++编译器,所以去官网选择安装codeblocks-16.01mingw-setup.exe 然后settings>Compiler ...

  6. stm32L011F3使用开发小记——开发坏境

    今日,因工作需要,使用到了stm32L011F3芯片,此芯片基于CM0+内核,属于低功耗芯片 开发平台可以免费用于KEILMDK,keil公司用免费的许可证,网址:https://www2.keil. ...

  7. Linux对大容量硬盘分区

    随着单块硬盘容量的增大和硬盘价格的下降,2TB的磁盘使用将很快会普及,由于传统的MBR方式存储分区表的方 式缺陷,将可能导致很多分区工具不能正确地读取大于2TB容量的硬盘而无法正常分区大容量硬盘.其实 ...

  8. Python虚拟机中的一般表达式(二)

    复杂内建对象的创建 在上一章Python虚拟机中的一般表达式(一)中,我们看到了Python是如何创建一个空的字典对象和列表对象,那么如果创建一个非空的字典对象和列表对象,Python的行为又是如何呢 ...

  9. Python选修课第二届Turtle绘图大赛~~画猫猫

    (a)20161401167 夏思敏 20161401179 段梦格 (b)代码执行视频链接 点击查看:Python使用turtle库画猫猫 (c)程序源码 import turtle turtle. ...

  10. web安全测试---WebScarab工具介绍

    1.1      Webscarab [功能] WebScarab是一个用来分析使用HTTP和HTTPS协议的应用程序框架.其原理很简单,WebScarab可以记录它检测到的会话内容(请求和应答),并 ...