hud 4746 莫比乌斯反演
Mophues
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 327670/327670 K (Java/Others)
Total Submission(s): 579 Accepted Submission(s): 235
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.
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).
10 10 0
10 10 1
93
#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 莫比乌斯反演的更多相关文章
- HDU 4746 (莫比乌斯反演) Mophues
这道题看巨巨的题解看了好久,好久.. 本文转自hdu4746(莫比乌斯反演) 题意:给出n, m, p,求有多少对a, b满足gcd(a, b)的素因子个数<=p,(其中1<=a<= ...
- HDU 4746 莫比乌斯反演+离线查询+树状数组
题目大意: 一个数字组成一堆素因子的乘积,如果一个数字的素因子个数(同样的素因子也要多次计数)小于等于P,那么就称这个数是P的幸运数 多次询问1<=x<=n,1<=y<=m,P ...
- HDU 4746 Mophues (莫比乌斯反演应用)
Mophues Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 327670/327670 K (Java/Others) Total ...
- HDU 4746 Mophues【莫比乌斯反演】
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4746 题意: 1≤x,y≤n , 求gcd(x,y)分解后质因数个数小于等k的(x,y)的对数. 分 ...
- Mophues HDU - 4746 (莫比乌斯反演)
Mophues \[ Time Limit: 10000 ms\quad Memory Limit: 262144 kB \] 题意 求出满足 \(gcd\left(a,b\right) = k\), ...
- HDU 4746 Mophues(莫比乌斯反演)题解
题意: \(Q\leq5000\)次询问,每次问你有多少对\((x,y)\)满足\(x\in[1,n],y\in[1,m]\)且\(gcd(x,y)\)的质因数分解个数小于等于\(p\).\(n,m, ...
- hdu1695 GCD(莫比乌斯反演)
题意:求(1,b)区间和(1,d)区间里面gcd(x, y) = k的数的对数(1<=x<=b , 1<= y <= d). 知识点: 莫比乌斯反演/*12*/ 线性筛求莫比乌 ...
- BZOJ 2154: Crash的数字表格 [莫比乌斯反演]
2154: Crash的数字表格 Time Limit: 20 Sec Memory Limit: 259 MBSubmit: 2924 Solved: 1091[Submit][Status][ ...
- BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】
2301: [HAOI2011]Problem b Time Limit: 50 Sec Memory Limit: 256 MBSubmit: 4032 Solved: 1817[Submit] ...
随机推荐
- python 遍历list
#!/usr/bin/env python# -*- coding: utf-8 -*-if __name__ == '__main__': list = ['html', 'js', 'css ...
- checkbox点击选中,再点击取消,并显示在文本框中
function checkItem(e,itemId) { var item = document.getElementById(itemId); var $items = $(item); if ...
- 【 android】When an app is installed on the external storage
When an app is installed on the external storage: The .apk file is saved to the external storage, bu ...
- Python开发环境与开发软件的安装
Python开发的必要因素: 开发软件:PyCharm 社区版 PyCharm安装过程: 首先去官网下载:(链接为: https://www.jetbrains.com/pycharm/downlo ...
- python向上取整 向下取整
向上取整 ceil() 函数返回数字的向上取整整数,就是返回大于等于变量的最近的整数. ceil()是不能直接访问的,需要导入 math 模块. import math math.ceil( x ) ...
- vim中,在编辑模式下如何快速移动光标
编辑 ~/.vimrc 配置文件,加入如下行,编辑模式下自定义的快捷键 inoremap <C-o> <Esc>o inoremap <C-l> <Righ ...
- set 方法总结整理
#!/usr/bin/env python __author__ = "lrtao2010" #Python 3.7.0 集合常用方法 #集合是无序的,元素不能重复,元素只能是数字 ...
- SQL语句小练习
一.创建如下表结构(t_book) Id 主键 自增一 bookName 可变长 20 Price 小数 Author 可变长20 bookTypeId 图书类 ...
- hashable与unhashable
不可哈希(unhashable):就是指其可变,如列表.字典等,都能原地进行修改. 可哈希(hashable):不可变,如字符串.元组那样,不能原地修改. 利用set()和{}建立集合时,要求集合中的 ...
- asm-offset.h 生成
转自:https://blog.csdn.net/linglongqiongge/article/details/50008301 http://www.cnblogs.com/wendellyi/p ...