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. MFC:Unicode和多字节字符集下 CString和char的转化(MFC中)

    2011-05-16 00:10 1166人阅读 评论(0) 收藏 举报 mfcdelete Unicode下 CString转TCHAR TCHAR* szMsg = new TCHAR[wcsle ...

  2. TreeMap 底层是红黑树 排序是根据key值进行的 添加元素时异常 Comparable异常 Comparator比较自定义对象放在键的位置

    package com.swift; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; ...

  3. Check for Palindromes-freecodecamp算法题目

    Check for Palindromes(检查回文字符串) 要求 给定的字符串是回文,返回true,反之,返回false.(如果一个字符串忽略标点符号.大小写和空格,正着读和反着读一模一样,那么这个 ...

  4. 【线段树 泰勒展开】Codechef April Challenge 2018 Chef at the Food Fair

    第一次写泰勒展开:本地和CC差距好大 题目大意 大厨住的城市里办了一场美食节.一条街上开设了$N$个摊位,编号为$1∼N$.这天开始时,第$i$个摊位的食物会导致食物中毒的概率是$P_i$.在这一天中 ...

  5. Mycat高可用解决方案二(主从复制)

    Mycat高可用解决方案二(主从复制) 系统部署规划 名称 IP 主机名称 用户名/密码 配置 mysql主节点 192.168.199.110 mysql-01 root/hadoop 2核/2G ...

  6. 为PHPcms扩展json采集

    最近想用phpcms做个新闻类网站,做采集的时候发现没有json的选项,于是自己动手,增加了采集json选项. 由于有的网站并不是纯json传输,而是jsonp,因此我把json,jsonp数据都当做 ...

  7. Word 借助VBA一键实现插入交叉引用

    最近写论文的时候,经常需要向上或向下插入题注的交叉引用,word 自带的界面往往需要操作多次,才能实现插入.而平时使用较多的只是交叉引用附近的题注,比如如图1.1所示,在图1.1中等,距离较远的引用则 ...

  8. Running OOM killer script for process 32248 for Solr on port 8983

    Running OOM killer script for process 32248 for Solr on port 8983 分析1 https://blog.csdn.net/qq_41665 ...

  9. POJ:2109-Power of Cryptography(关于double的误差)

    Power of Cryptography Time Limit: 1000MS Memory Limit: 30000K Description Current work in cryptograp ...

  10. 1036: [ZJOI2008]树的统计Count(树链剖分)

    1036: [ZJOI2008]树的统计Count Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 19830  Solved: 8067[Submit ...