ural 1091. Tmutarakan Exams(容斥)
http://acm.timus.ru/problem.aspx?
space=1&num=1091
从1~s中选出k个数,使得k个数的最大公约数大于1,问这种取法有多少种。
(2<=k <= s<=50)
同素数四元组问题类似,能够參考http://blog.csdn.net/u013081425/article/details/40653895
仅仅只是这里是选出k个。不是4个。
#include <stdio.h>
#include <iostream>
#include <map>
#include <set>
#include <bitset>
#include <list>
#include <stack>
#include <vector>
#include <math.h>
#include <string.h>
#include <queue>
#include <string>
#include <stdlib.h>
#include <algorithm>
#define LL __int64
//#define LL long long
#define eps 1e-9
#define PI acos(-1.0)
using namespace std;
const int maxn = 100010; int k,s;
int num[55];
int prime[] = {15,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
int cnt[55];
LL c[55][55]; void init()
{
memset(c,0,sizeof(c));
for(int i = 1; i <= 25; i++)
{
for(int j = 0; j <= i; j++)
{
if(j == 0 || j == i)
c[i][j] = 1;
else if(j == 1)
c[i][j] = i;
else
c[i][j] = c[i-1][j-1] + c[i-1][j];
}
}
} void dfs(int st, int val, int num)
{
if(val > 50) return;
cnt[val] = num&1 ? 1 : -1;
for(int i = st; i <= prime[0]; i++)
{
if(prime[i]*val > 50)
break;
dfs(i+1,val*prime[i],num+1);
}
} int main()
{
init();
memset(cnt,0,sizeof(cnt));
dfs(1,1,0);
while(~scanf("%d %d",&k,&s))
{
for(int d = 2; d <= s; d++)
{
num[d] = s/d;
} LL ans = 0; for(int d = 2; d <= s; d++)
{
if(num[d] < k)
break;
if(cnt[d])
{
ans += cnt[d]*c[num[d]][k];
}
}
if(ans >= 10000)
printf("10000\n");
else
printf("%I64d\n",ans);
}
return 0;
}
ural 1091. Tmutarakan Exams(容斥)的更多相关文章
- ural 1091. Tmutarakan Exams(容斥原理)
1091. Tmutarakan Exams Time limit: 1.0 secondMemory limit: 64 MB University of New Tmutarakan trains ...
- F - Tmutarakan Exams URAL - 1091 -莫比乌斯函数-容斥 or DP计数
F - Tmutarakan Exams 题意 : 从 < = S 的 数 中 选 出 K 个 不 同 的 数 并 且 gcd > 1 .求方案数. 思路 :记 录 一 下 每 个 数 的 ...
- Ural 1091 Tmutarakan Exams
Tmutarakan Exams Time Limit: 1000ms Memory Limit: 16384KB This problem will be judged on Ural. Origi ...
- ural 1091. Tmutarakan Exams 和 codeforces 295 B. Greg and Graph
ural 1091 题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1091 题意是从1到n的集合里选出k个数,使得这些数满足gcd大于1 ...
- URAL - 1091 Tmutarakan Exams (简单容斥原理)
题意:K个不同数组成的集合,每个数都不超过S且它们的gcd>1.求这样的数的个数 分析:从2开始枚举gcd,但这样会发生重复.譬如,枚举gcd=2的集合个数和gcd=3的集合个数,枚举6的时候就 ...
- URAL1091. Tmutarakan Exams(容斥)
1091 容斥原理 #include <iostream> #include<cstdio> #include<cstring> #include<algor ...
- 1091. Tmutarakan Exams
1091. Tmutarakan Exams Time limit: 1.0 secondMemory limit: 64 MB University of New Tmutarakan trains ...
- 容斥原理--计算并集的元素个数 URAL 1091
在计数时,必须注意没有重复,没有遗漏.为了使重叠部分不被重复计算,人们研究出一种新的计数方法,这种方法的基本思想是:先不考虑重叠的情况,把包含于某内容中的所有对象的数目先计算出来,然后再把计数时重复计 ...
- Tmutarakan Exams URAL - 1091(莫比乌斯函数 || 容斥)
题意: 求1 - s 中 找出k个数 使它们的gcd > 1 求这样的k个数的对数 解析: 从每个素数的倍数中取k个数 求方案数 然后素数组合,容斥一下重的 奇加偶减 莫比乌斯函数的直接套模 ...
随机推荐
- Go语言中的RPC调用
首先,说一下目录结构: 一.HttpRPC 1.建立服务文件 /*Go RPC的函数只有符合下面的条件才能被远程访问,不然会被忽略,详细的要求如下: 函数必须是导出的(首字母大写) 必须有两个导出类型 ...
- Wrong FS: hdfs://xxx/xxx expected: file:///
Eclipse调用HDFS API上传文件时出现了如下错误: Exception in thread "main" java.lang.IllegalArgumentExcepti ...
- 给mysql配置phpmyadmin可视化管理工具
1.配置IIS管理器1.控制面板——程序——程序和功能——启用或关闭windows功能并稍稍等候2.internet information services3.勾选ftp服务器.web管理工具.应用 ...
- tablib把数据导出为Excel、JSON、CSV等格式的Py库(写入数据并导出exl)
#tablib把数据导出为Excel.JSON.CSV等格式的Py库 #python 3 import tablib #定义列标题 headers = ('1列', '2列', '3列', '4列', ...
- RHEL7 添加网卡并设置多个IP地址
首先在虚拟机管理界面中给该虚拟机添加一块虚拟网卡,VirtualBox虚拟机中要shutdown才能添加. [root@rhel7 ~]# nmcli device show | grep -i de ...
- Linux 系统lsblk和blkid命令
lsblk命令用于以树状的格式显示所有可用的块设备信息: [root@rhel7 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda : 10G ...
- T-Sql常用语句
1.用bcp导出txt数据 DECLARE ), ) BEGIN , ), '/', '-'); SET @bcp = 'bcp WebStat.dbo.[PV_HIS_' + @date + '] ...
- 网站PV、UV以及查看方法
网站PV.UV以及查看方法 一.名词解释 PV:PV 是Page Views的缩写,即页面浏览量,用户每一次对网站中的每个网页访问均被记录一次.注意,访客每刷新一次页面,pv就增加一次. UV:UV是 ...
- 【PHP5.3+】获取getCurrentUrl()中 的地址url
1.在控制器中调用其他 扩展或者类 的方法时候,getCurrentUrl()方法 是获取的[当前控制器下方法]的路由,不是[其他 扩展或者类 方法]的路由!!! 2.getCurrentUrl()方 ...
- ios中摄像头和图片调用
推荐文章 http://www.xuanyusong.com/archives/1493 http://blog.csdn.net/ryantang03/article/details/7830996