1091

容斥原理

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
using namespace std;
int p[],g,f[],q[],o,vis[],pa[],n,kk;
#define LL long long
void init()
{
int i,j;
for(i = ; i < ; i++)
if(!f[i])
for(j = i+i ; j < ; j+=i)
f[j] = ;
for(i = ; i < ; i++)
if(!f[i])
p[++g] = i;
}
LL find(int num,int k)
{
if(num<k) return ;
int i,x=k;
LL s = ;
for(i = ; i <= k ; i++)
{
s*=num;
num--;
while(x>&&s%x==)
{
s/=x;
x--;
}
}
return s;
}
LL dfs(int k,int v,int a)
{
int i,j;
LL s=;
if(a==o+&&v==k)
{
for(i = ; i <= n ; i++)
{
for(j = ; j <= v ; j++)
if(i%pa[j]!=)
break;
if(j==v+)
s++;
}
s = find(s,kk);
return s;
}
if(a>o) return ;
pa[v+] = p[a];
s+=dfs(k,v+,a+);
s+=dfs(k,v,a+);
return s;
}
int main()
{
int i,j;
init();
cin>>kk>>n;
LL s=;
for(i = ; i <= g ; i++)
{
int num = ;
for(j = ; j <= n ; j++)
if(j%p[i]==)
num++;
if(num<kk) continue;
q[++o] = p[i];
s+=find(num,kk);
}
for(i = ; i <= o ; i++)
{
memset(vis,,sizeof(vis));
LL pp=dfs(i,,);
if(i%==)
s-=pp;
else
s+=pp;
}
if(s>=)
cout<<""<<endl;
else
cout<<s<<endl;
return ;
}

URAL1091. Tmutarakan Exams(容斥)的更多相关文章

  1. ural 1091. Tmutarakan Exams(容斥)

    http://acm.timus.ru/problem.aspx? space=1&num=1091 从1~s中选出k个数,使得k个数的最大公约数大于1,问这种取法有多少种. (2<=k ...

  2. Tmutarakan Exams URAL - 1091(莫比乌斯函数 || 容斥)

    题意: 求1 - s 中 找出k个数 使它们的gcd  > 1 求这样的k个数的对数 解析: 从每个素数的倍数中取k个数  求方案数 然后素数组合,容斥一下重的 奇加偶减 莫比乌斯函数的直接套模 ...

  3. F - Tmutarakan Exams URAL - 1091 -莫比乌斯函数-容斥 or DP计数

    F - Tmutarakan Exams 题意 : 从 < = S 的 数 中 选 出 K 个 不 同 的 数 并 且 gcd > 1 .求方案数. 思路 :记 录 一 下 每 个 数 的 ...

  4. POJ1091跳蚤(容斥 + 唯一分解 + 快速幂)

      题意:规定每次跳的单位 a1, a2, a3 …… , an, M,次数可以为b1, b2, b3 …… bn, bn + 1, 正好表示往左,负号表示往右, 求能否调到左边一位,即 a1* b1 ...

  5. HDU 4059 容斥初步练习

    #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> ...

  6. HDU 4336 Card Collector (期望DP+状态压缩 或者 状态压缩+容斥)

    题意:有N(1<=N<=20)张卡片,每包中含有这些卡片的概率,每包至多一张卡片,可能没有卡片.求需要买多少包才能拿到所以的N张卡片,求次数的期望. 析:期望DP,是很容易看出来的,然后由 ...

  7. 【BZOJ-4455】小星星 容斥 + 树形DP

    4455: [Zjoi2016]小星星 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 204  Solved: 137[Submit][Status] ...

  8. cf#305 Mike and Foam(容斥)

    C. Mike and Foam time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  9. UVa12633 Super Rooks on Chessboard(容斥 + FFT)

    题目 Source http://acm.hust.edu.cn/vjudge/problem/42145 Description Let’s assume there is a new chess ...

随机推荐

  1. confusing uv

    in a projection u from letf to right is 0---1 in another proj u is the same but when i output u in r ...

  2. RCC 2014 Warmup (Div. 2)

    一场很很多HACK的比赛,PREtest太弱了,真的很多坑!平时练习的时候很少注意这些东西了! A:开始一直在模拟,后来发现自己的思路逻辑很乱,果然做比赛不给力! 直接在代码中解释了 #include ...

  3. LCIS(m*n) 最长公共上升子序列

    详见:http://wenku.baidu.com/view/3e78f223aaea998fcc220ea0n3的: for(int i=1;i<=n;i++)             for ...

  4. const int *p与int *const p的区别(转:csdn,suer0101)

    本文只是一篇学习笔记,是看了<彻底搞定C指针>中的相关篇幅后的一点总结,仅此而已! 一.先搞清const int *p与int const *p的区别 它们的区别就是:没有区别!! 无论谁 ...

  5. 《暗黑世界GM管理后台系统》部署+功能说明文档

    http://www.9miao.com/product-10-1073.html <暗黑世界GM管理后台系统>部署+功能说明文档 <暗黑世界GM管理后台系统>部署+功能说明文 ...

  6. spring事务认识

    Spring配置异常回滚采用的是rollback-for=“BusinessException”.来源于java的检查性异常.非检查性异常的区别.使用spring难免要用到spring的事务管理,要用 ...

  7. Python编程指南 chapter 1

    1.python使用方括号[]来存取一个序列中的某个数据项,像字符串.列表等包含若干数据项的序列都采用这种方法. 2.强制类型转换,int('24234'),str(235) 3.python中没有变 ...

  8. HDU 3518 Boring counting(后缀数组,字符处理)

    题目 参考自:http://blog.sina.com.cn/s/blog_64675f540100k9el.html 题目描述: 找出一个字符串中至少重复出现两次的字串的个数(重复出现时不能重叠). ...

  9. 判断一个字符串在至多删除k个字符后是否为回文串

    转自: http://www.careercup.com/question?id=6287528252407808 问题描述: A k-palindrome is a string which tra ...

  10. 安装微软ASP.NET MVC 4,运行以下的包管理器控制台命令

    (菜鸟,勿喷,有错求指正)Asp.net  新建的类库中安装MVC4  .下面是步骤,1+2:打开程序包管理控制台,3:运行Install-Package Microsoft.AspNet.Mvc - ...