1091. Tmutarakan Exams

Time limit: 1.0 second
Memory limit: 64 MB
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 output
3 10
11
Problem Author: Stanislav Vasilyev
Problem Source: USU Open Collegiate Programming Contest March'2001 Senior Session

2000–2016 Timus Online Judge Team. All rights reserved.

思路:和http://www.cnblogs.com/zzuli2sjy/p/5467008.html一样;

  1 #include<stdio.h>
2 #include<string.h>
3 #include<iostream>
4 #include<algorithm>
5 #include<queue>
6 using namespace std;
7 typedef long long LL;
8 bool prime[100];
9 int ans[100];
10 int coutt[10000];
11 LL dp[60][60];
12 int ask[100];
13 int id[100];
14 queue<int>que;
15 int main(void)
16 {
17 int i,j,k,p,q;
18 dp[0][0]=1;
19 dp[1][0]=1;
20 dp[1][1]=1;
21 for(i=2; i<=60; i++)
22 {
23 for(j=0; j<=60; j++)
24 {
25 if(j==0||i==j)
26 {
27 dp[i][j]=1;
28 }
29 else dp[i][j]=dp[i-1][j-1]+dp[i-1][j];
30 }
31 }
32 for(i=2; i<=10; i++)
33 {
34 if(!prime[i])
35 {
36 for(j=i; i*j<=50; j++)
37 {
38 prime[i*j]=true;
39 }
40 }
41 }
42 int cnt=0;
43 for(i=2; i<=50; i++)
44 {
45 if(!prime[i])
46 {
47 ans[cnt++]=i;
48 }
49 }
50 while(scanf("%d %d",&p,&q)!=EOF)
51 { int s;
52 memset(coutt,0,sizeof(coutt));
53 for(s=2; s<=q; s++)
54 {
55 int cc=s;
56 int flag=0;
57 int t=0;
58 while(cc>1)
59 {
60 if(cc%ans[t]==0&&flag==0)
61 {
62 flag=1;
63 que.push(ans[t]);
64 cc/=ans[t];
65 }
66 else if(cc%ans[t]==0)
67 {
68 cc/=ans[t];
69 }
70 else
71 {
72 t++;
73 flag=0;
74 }
75 }
76 int vv=0;
77 while(!que.empty())
78 {
79 ask[vv++]=que.front();
80 que.pop();
81 }
82 for(i=1; i<=(1<<vv)-1; i++)
83 {
84 LL sum=1;
85 int dd=0;
86 for(j=0; j<vv; j++)
87 {
88 if(i&(1<<j))
89 {
90 dd++;
91 sum*=ask[j];
92 }
93 }
94 id[sum]=dd;
95 coutt[sum]++;
96
97 }
98 }
99 LL summ=0;
100 for(i=2; i<=50; i++)
101 {
102 if(id[i]%2&&coutt[i]>=p)
103 {
104 summ+=dp[coutt[i]][p];
105 }
106 else if(coutt[i]>=p)summ-=dp[coutt[i]][p];
107 }if(summ>=10000)summ=10000;
108 printf("%lld\n",summ);
109 }
110 return 0;
111 }

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

    Tmutarakan Exams Time Limit: 1000ms Memory Limit: 16384KB This problem will be judged on Ural. Origi ...

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

  4. ural 1091. Tmutarakan Exams(容斥)

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

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

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

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

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

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

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

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

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

  9. URAL1091. Tmutarakan Exams(容斥)

    1091 容斥原理 #include <iostream> #include<cstdio> #include<cstring> #include<algor ...

随机推荐

  1. 学习java的第二十六天

    一.今日收获 1.java完全学习手册第三章算法的3.2排序,比较了跟c语言排序上的不同 2.观看哔哩哔哩上的教学视频 二.今日问题 1.快速排序法的运行调试多次 2.哔哩哔哩教学视频的一些术语不太理 ...

  2. 『学了就忘』Linux文件系统管理 — 66、通过图形界面进行LVM分区

    目录 1.选择自定义分区 2.分配boot分区 3.创建LVM物理卷 4.生成卷组 5.创建逻辑卷 6.格式化安装 我们先用新安装Linux系统时的图形化界面,来演示一下LVM逻辑卷如何进行分区. 提 ...

  3. 『学了就忘』Linux启动引导与修复 — 68、Linux系统运行级别

    目录 1.Linux系统运行级别介绍 2.查看运行级别 3.修改当前系统的运行级别 4.系统默认运行级别 5./etc/rc.d/rc.local文件说明 1.Linux系统运行级别介绍 Linux默 ...

  4. 移动开发之h5学习大纲

    移动开发学习形式:授课.自学 1.html5 css3 htm5shiv.js response.js 2.流式布局 自适应布局 盒模型 弹性盒模型 响应式布局3.iscroll swiper boo ...

  5. Angular @Input讲解及用法

    1.什么是@input @input的作用是定义模块输入,是用来让父级组件向子组件传递内容. 2.@input用法 首先在子组件中将需要传递给父组件的变量用@input()修饰 需要在子组件ts文件i ...

  6. C++最小内积

    Description 向量是几何中的一个重要概念. 考虑两个向量 v1=(x1,x2,...,xn)和v2=(y1,y2,...,yn),向量的内积定义为 x1y1+x2y2+...+xnyn 例如 ...

  7. Output of C++ Program | Set 14

    Predict the output of following C++ program. Difficulty Level: Rookie Question 1 1 #include <iost ...

  8. Servlet(2):通过servletContext对象实现数据共享

    一,ServletContext介绍 web容器在启动时,它会为每一个web应用程序都创建一个ServletContext对象,它代表当前web应用 多个Servlet通过ServletContext ...

  9. Classs类

    Classs类如何获得 获得Class对象 方式一: 通过Object类中的getClass()方法 方式二: 通过 类名.class 获取到字节码文件对象( 方式三: 通过Class类中的方法(将类 ...

  10. Thymeleaf+layui+jquery复选框回显

    一.Thymeleaf+layui+jquery复选框回显 基于Thymeleaf模板下的layui+jquery复选框回显,主要是jquery.大致意思是:把数组转成JSON传到前台,再在前台转回数 ...