Ural 1091 Tmutarakan Exams
2015-09-29 21:02
323 查看
Tmutarakan Exams
Time Limit: 1000msMemory 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
3 10
Sample Output
11
Source
USU Open Collegiate Programming Contest March'2001 Senior Session解题:容斥原理
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int maxn = 52; LL c[maxn][maxn]; int p[] = {2,3,5,7,11,13,17,19,23,29}; void init() { c[0][0] = 1; for(int i = 1; i < maxn; ++i) { c[i][0] = c[i][i] = 1; for(int j = 1; j < i; ++j) c[i][j] = c[i-1][j] + c[i-1][j-1]; } } int main() { init(); int k,s; while(~scanf("%d%d",&k,&s)) { LL ret = 0; for(int i = 0; i < 10; ++i) { if(s/p[i] < k) { for(int j = 1; j < (1<<i); ++j) { int cnt = 0; LL tmp = 1; for(int t = 0; t < i; ++t) { if((j>>t)&1) { cnt++; tmp *= p[t]; } } if(cnt&1) ret += c[s/tmp][k]; else ret -= c[s/tmp][k]; } break; } } printf("%I64d\n",ret > 10000?10000:ret); } return 0; }
View Code
相关文章推荐
- Build CRUD Application with jQuery EasyUI
- 第二十三篇:UITableView,UIScrollView,NSTimer,UIButton综合应用代码---团购
- ubuntu 解决“无法获得锁 /var/lib/dpkg/lock -open (11:资源暂时不可用)”的方法
- Android JNI 使用的数据结构JNINativeMethod详解
- 结对项目代码复审
- 解决div里插入img下边缝隙问题
- 使用 native2ascii.exe 将java utf-8编码批量转换为 ANSI.
- 关于mysql语句的一道笔试题
- Android进阶笔记01:Android 网络请求库的比较及实战(一)
- 一起talk C栗子吧(第四十九回:C语言实例--最小生成树一)
- 数据库的连接代码
- 【ShancoLove】带你看数据结构——第二课:线性表顺序结构
- Codeforces 7C
- CSF Framework
- 实现秒杀的几个想法(续)
- 通俗易懂的来讲讲DOM
- hdu 5461 Largest Point(水)
- iOS swift-1
- 用两个队列实现栈
- test8.17