Tmutarakan Exams URAL - 1091(莫比乌斯函数 || 容斥)
题意:
求1 - s 中 找出k个数 使它们的gcd > 1 求这样的k个数的对数
解析:
从每个素数的倍数中取k个数 求方案数
然后素数组合,容斥一下重的 奇加偶减
莫比乌斯函数的直接套模板就好了 容斥函数为 mu[i] * -1
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <cctype>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define rb(a) scanf("%lf", &a)
#define rf(a) scanf("%f", &a)
#define pd(a) printf("%d\n", a)
#define plld(a) printf("%lld\n", a)
#define pc(a) printf("%c\n", a)
#define ps(a) printf("%s\n", a)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff;
LL c[maxn][maxn];
int prime[maxn + ];
int cnt, s, k;
void get_prime()
{
mem(prime, );
for(int i=; i<=maxn; i++)
{
if(!prime[i]) prime[++prime[]] = i;
for(int j=; j<=prime[] && prime[j] <= maxn/i; j++)
{
prime[prime[j]*i] = ;
if(i % prime[j] == ) break;
}
}
} void init()
{
mem(c, );
c[][] = c[][] = ;
for(int i = ; i < maxn; i++)
{
c[i][] = ;
for(int j = ; j <= i; j++)
c[i][j] = c[i - ][j] + c[i - ][j - ];
}
} LL get_cnt()
{
LL res = ;
for(int i = ; i < ( << cnt); i++)
{
LL tmp = , ans2 = ;
for(int j = ; j <= cnt; j++)
{
if(((i >> (j - )) & ) == ) continue;
tmp *= prime[j];
ans2++;
}
// cout << tmp << endl;
// if(s / tmp < k) continue;
if(ans2 & ) res += c[s / tmp][k];
else res -= c[s / tmp][k];
}
return res;
} int main()
{
init();
get_prime();
while(cin >> k >> s)
{
LL res = ;
cnt = ;
for(int i = ; i < ; i++)
{
if(s / prime[i] < k) break;
cnt++;
}
LL ans = get_cnt();
if(ans > ) ans = ;
cout << ans << endl; } return ;
}
Tmutarakan Exams URAL - 1091(莫比乌斯函数 || 容斥)的更多相关文章
- F - Tmutarakan Exams URAL - 1091 -莫比乌斯函数-容斥 or DP计数
F - Tmutarakan Exams 题意 : 从 < = S 的 数 中 选 出 K 个 不 同 的 数 并 且 gcd > 1 .求方案数. 思路 :记 录 一 下 每 个 数 的 ...
- HDU 6053 TrickGCD 莫比乌斯函数/容斥/筛法
题意:给出n个数$a[i]$,每个数可以变成不大于它的数,现问所有数的gcd大于1的方案数.其中$(n,a[i]<=1e5)$ 思路:鉴于a[i]不大,可以想到枚举gcd的值.考虑一个$gcd( ...
- BZOJ 2440 莫比乌斯函数+容斥+二分
2440: [中山市选2011]完全平方数 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 5473 Solved: 2679[Submit][Sta ...
- C - Visible Trees HDU - 2841 -莫比乌斯函数-容斥
C - Visible Trees HDU - 2841 思路 :被挡住的那些点(x , y)肯定是 x 与 y不互质.能够由其他坐标的倍数表示,所以就转化成了求那些点 x,y互质 也就是在 1 - ...
- Relatively Prime Powers CodeForces - 1036F (莫比乌斯函数容斥)
Relatively Prime Powers CodeForces - 1036F Consider some positive integer xx. Its prime factorizatio ...
- 完全平方数 HYSBZ - 2440 (莫比乌斯函数容斥)
完全平方数 HYSBZ - 2440 小 X 自幼就很喜欢数.但奇怪的是,他十分讨厌完全平方数.他觉得这些 数看起来很令人难受.由此,他也讨厌所有是完全平方数的正整数倍的数.然而 这丝毫不影响他对其他 ...
- HDU 1695 GCD 欧拉函数+容斥定理 || 莫比乌斯反演
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- bzoj2440 完全平方数 莫比乌斯值+容斥+二分
莫比乌斯值+容斥+二分 /** 题目:bzoj2440 完全平方数 链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2440 题意:求第k个小x数 ...
- hdu1695(莫比乌斯)或欧拉函数+容斥
题意:求1-b和1-d之内各选一个数组成数对.问最大公约数为k的数对有多少个,数对是有序的.(b,d,k<=100000) 解法1: 这个能够简化成1-b/k 和1-d/k 的互质有序数对的个数 ...
随机推荐
- 二、xadmin----简单使用
1.中文设置: settings.py中直接配置: LANGUAGE_CODE = "zh-hans" TIME_ZONG = "Asia/Shanghai" ...
- xadmin后台页面的自定制
01-自定制页面 注:最近找到了更好的解决办法:重写钩子函数版 https://www.cnblogs.com/pgxpython/p/10593507.html 需求背景:根据要实现的功能需求,x ...
- STL vector用法
基本操作 1.构造函数 vector():创建一个空vector vector(int nSize):创建一个vector,元素个数为nSize vector(int nSize,const t&am ...
- c++入门之再次探讨类属性
精辟博文:https://blog.csdn.net/msdnwolaile/article/details/51923859(转载,仅供学习|!)
- Springboot通过cors解决跨域问题(解决spring security oath2的/oauth/token跨域问题)
@Bean public CorsFilter corsFilter() { final UrlBasedCorsConfigurationSource source = new UrlBasedCo ...
- vue echarts 动态数据
安装echarts依赖 npm install echarts -S 或者使用国内的淘宝镜像: 安装 npm install -g cnpm --registry=https://registry.n ...
- Spring Boot 中使用 @Transactional 注解配置事务管理
事务管理是应用系统开发中必不可少的一部分.Spring 为事务管理提供了丰富的功能支持.Spring 事务管理分为编程式和声明式的两种方式.编程式事务指的是通过编码方式实现事务:声明式事务基于 AOP ...
- 【学习总结】【Java】Git学习-上传本地已有代码到GitHub
< Git学成归来后的第一次实战 > 上传本地已有代码到GitHub 以之前学了一小半的Java基础教程代码为例 <深坑预警:在GitHub新建仓库那一步,不要勾选readme,不然 ...
- 解决linux用户切换失败 su:execute /usr/bin 没有权限
问题描述: 回宿舍前,在root用户中安装fish,并修改其shell为fish.回宿舍之后,在图形界面用root用户进行登陆,莫名其妙登陆失败.没有任何提示信息,直接回到登陆界面.用非root用户登 ...
- 在tomcat8.0.x和tomcat9.0.x之间么突然冒出个tomcat 8.5
Apache Tomcat 8 (8.5.38) - Documentation Indexhttps://tomcat.apache.org/tomcat-8.5-doc/index.html to ...