Tmutarakan Exams

Time Limit: 1000ms
Memory Limit: 16384KB

This problem will be judged on Ural. Original ID: 1091
64-bit integer IO format: %lld      Java class name: (Any)

 
University of New Tmutarakan trains the first-class specialists in mental arithmetic. To enter the University you should master arithmetic perfectly. One of the entrance exams at the Divisibility Department is the following. Examinees are asked to find K different numbers that have a common divisor greater than 1. All numbers in each set should not exceed a given number S. The numbers K and S are announced at the beginning of the exam. To exclude copying (the Department is the most prestigious in the town!) each set of numbers is credited only once (to the person who submitted it first).
Last year these numbers were K=25 and S=49 and, unfortunately, nobody passed the exam. Moreover, it was proved later by the best minds of the Department that there do not exist sets of numbers with the required properties. To avoid embarrassment this year, the dean asked for your help. You should find the number of sets of K different numbers, each of the numbers not exceeding S, which have a common divisor greater than 1. Of course, the number of such sets equals the maximal possible number of new students of the Department.
 

Input

The input contains numbers K and S (2 ≤ K ≤ S ≤ 50).
 

Output

You should output the maximal possible number of the Department's new students if this number does not exceed 10000 which is the maximal capacity of the Department, otherwise you should output 10000.
 

Sample Input

  1. 3 10

Sample Output

  1. 11

Source

 
解题:容斥原理
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. const int maxn = ;
  5. LL c[maxn][maxn];
  6. int p[] = {,,,,,,,,,};
  7. void init() {
  8. c[][] = ;
  9. for(int i = ; i < maxn; ++i) {
  10. c[i][] = c[i][i] = ;
  11. for(int j = ; j < i; ++j)
  12. c[i][j] = c[i-][j] + c[i-][j-];
  13. }
  14. }
  15. int main() {
  16. init();
  17. int k,s;
  18. while(~scanf("%d%d",&k,&s)) {
  19. LL ret = ;
  20. for(int i = ; i < ; ++i) {
  21. if(s/p[i] < k) {
  22. for(int j = ; j < (<<i); ++j) {
  23. int cnt = ;
  24. LL tmp = ;
  25. for(int t = ; t < i; ++t) {
  26. if((j>>t)&) {
  27. cnt++;
  28. tmp *= p[t];
  29. }
  30. }
  31. if(cnt&) ret += c[s/tmp][k];
  32. else ret -= c[s/tmp][k];
  33. }
  34. break;
  35. }
  36. }
  37. printf("%I64d\n",ret > ?:ret);
  38. }
  39. return ;
  40. }

Ural 1091 Tmutarakan Exams的更多相关文章

  1. ural 1091. Tmutarakan Exams(容斥原理)

    1091. Tmutarakan Exams Time limit: 1.0 secondMemory limit: 64 MB University of New Tmutarakan trains ...

  2. 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 ...

  3. ural 1091. Tmutarakan Exams(容斥)

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

  4. URAL - 1091 Tmutarakan Exams (简单容斥原理)

    题意:K个不同数组成的集合,每个数都不超过S且它们的gcd>1.求这样的数的个数 分析:从2开始枚举gcd,但这样会发生重复.譬如,枚举gcd=2的集合个数和gcd=3的集合个数,枚举6的时候就 ...

  5. 1091. Tmutarakan Exams

    1091. Tmutarakan Exams Time limit: 1.0 secondMemory limit: 64 MB University of New Tmutarakan trains ...

  6. 容斥原理--计算并集的元素个数 URAL 1091

    在计数时,必须注意没有重复,没有遗漏.为了使重叠部分不被重复计算,人们研究出一种新的计数方法,这种方法的基本思想是:先不考虑重叠的情况,把包含于某内容中的所有对象的数目先计算出来,然后再把计数时重复计 ...

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

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

  8. 2014 Super Training #3 H Tmutarakan Exams --容斥原理

    原题: URAL 1091  http://acm.timus.ru/problem.aspx?space=1&num=1091 题意:要求找出K个不同的数字使他们有一个大于1的公约数,且所有 ...

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

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

随机推荐

  1. redis在linux安装和开机启动和结合php运用方法一

    第一部分:安装redis 希望将redis安装到此目录 1 /usr/local/redis 希望将安装包下载到此目录 1 /usr/local/src 那么安装过程指令如下: 1 2 3 4 5 6 ...

  2. Linux安装PHP环境

    简介: PHP(外文名:PHP: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言.语法吸收了C语言.Java和Perl的特点,利于学习,使用广泛,主要 ...

  3. POJ 2773 欧几里得

    思路: 若a和b互素的话,则b*t+a和b一定互素 用周期性做就好了 //By SiriusRen #include <cstdio> using namespace std; ],m,k ...

  4. 最短路 Codeforces Round #103 (Div. 2) D. Missile Silos

    题目传送门 /* 最短路: 不仅扫描边,还要扫描点:点有两种情况,一种刚好在中点,即从u,v都一样,那么最后/2 还有一种是从u,v不一样,两种的距离都是l 模板错了,逗了好久:( */ #inclu ...

  5. Spring.Net学习笔记(5)-集合注入

    一.开发环境 系统:Win10 编译器:VS2013 .net版本:.net framework4.5 二.涉及程序集 Spring.Core.dll 1.3.1 Common.Loggin.dll ...

  6. python自动化--语言基础三字典、函数、全局/局部变量

    字典 dict1 = {,'class':'first'} print(dict1.keys()) #打印所有的key值 print(dict1.values()) #打印所有的values值 pri ...

  7. UVM基础之---------uvm report 机制分析

    uvm 中的信息报告机制相对来说比较简单,功能上来说主要分为两部分: 第一通过ID对component的信息报告冗余级别进行控制,针对每个冗余级别进行不同的行为控制.这部分工作主要由uvm_repor ...

  8. Hue - Error loading MySQLdb module: libmysqlclient.so.20: cannot open shared object file: No such file or

    解决下面两点异常 >> 1. Hue页面 点击DB 查询时弹出: Error loading MySQLdb module: libmysqlclient.so.20: cannot op ...

  9. CUDA 显存操作:CUDA支持的C++11

    CUDA9的编译器和语言改进 使用CUDA 9,nvcc编译器增加了对C ++ 14的支持,其中包括新功能 通用的lambda表达式,其中使用auto关键字代替参数类型; auto lambda = ...

  10. 【OpenCV】像素操作的数字图像处理

    之前几天捣鼓matlab,用来处理数字图像,矩阵操作什么的,如果忘记线性代数就真的GG了. 在用了matlab被深深地吐槽之后,决定改用opencv,C++貌似也是处理数字图像的很好的工具 1. 在u ...