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 的互质有序数对的个数 ...
随机推荐
- Leetcode 143. Reorder List(Medium)
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do thi ...
- 建立一个单链表,并删除链表中值为W的元素
#include<iostream> #include<algorithm> #include<string.h> #include<stdio.h> ...
- CSS scroll-behavior属性: 滚动框指定滚动行为
概念 当用户手动导航或者 CSSOM scrolling API 触发滚动操作时,CSS 属性 scroll-behavior 为一个滚动框指定滚动行为,其他任何的滚动,例如那些由于用户行为而产生的滚 ...
- poj2226 Muddy Fields 填充棒子(二分匹配)
参考博客:https://blog.csdn.net/liujc_/article/details/51287019 参考博客:https://blog.csdn.net/acdreamers/art ...
- stl stack用法
栈后进先出 #include<iostream> #include<algorithm> #include<cstdio> #include<stack> ...
- Mike and gcd problem CodeForces - 798C (贪心思维+数论)
题目链接 比较棒的一道题, 题意: 给你一个N个数的数组,让你用尽量少的操作使整个数组的gcd大于1,即gcd(a1 ,a2,,,,an) > 1 如果可以输出YES和最小的次数,否则输出NO ...
- mysql处理重复数据
有些 MySQL 数据表中可能存在重复的记录,有些情况我们允许重复数据的存在,但有时候我们也需要删除这些重复的数据. 防止表中出现重复数据 你可以在MySQL数据表中设置指定的字段为 PRIMARY ...
- 容器化 — 基于Docker技术容器云
导读:本文介绍了基于Docker技术的企业级应用容器平台,从云的定义.云服务分类,到用友云PaaS基础平台.平台总体架构.架构预览.部署架构.平台核心价值和核心竞争力,阐述PaaS基础平台成为广大传统 ...
- 福州大学软件工程1816 | W班 第7次作业成绩排名
写在前面 汇总成绩排名链接 1.作业链接 第七次作业--项目需求分析(团队) 2.评分准则 本次作业映射总分为100分+贡献度得分,由以下部分组成: 引言(5 points) . 用户场景(15 po ...
- centos7 network eno16777736
Network service not running - eno16777736 not activated - CentOShttps://www.centos.org/forums/viewto ...