zoukankan      html  css  js  c++  java
  • ural 1091. Tmutarakan Exams 容斥

    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 ≤ KS ≤ 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

    inputoutput
    3 10
    
    11
    

    Problem Author: Stanislav Vasilyev
    Problem Source: USU Open Collegiate Programming Contest March'2001 Senior Session

    题目大意:求k个数的公约数 > 1有多少对,这些数不会超过S;

    思路:由于数很少我们可以直接判断出有哪些数的倍数是两个约数的公倍数

            2, 3共同的约数为6

       2, 5 ~10

       2, 7 ~14

       2, 11 ~22

       3 , 5~15

       3, 7 ~21

       然后再减去这些数就好

     1 #include <iostream>
     2 #include <sstream>
     3 #include <fstream>
     4 #include <string>
     5 #include <vector>
     6 #include <deque>
     7 #include <queue>
     8 #include <stack>
     9 #include <set>
    10 #include <map>
    11 #include <algorithm>
    12 #include <functional>
    13 #include <utility>
    14 #include <bitset>
    15 #include <cmath>
    16 #include <cstdlib>
    17 #include <ctime>
    18 #include <cstdio>
    19 #include <cstring>
    20 #define FOR(i, a, b)  for(int i = (a); i <= (b); i++)
    21 #define RE(i, n) FOR(i, 1, n)
    22 #define FORP(i, a, b) for(int i = (a); i >= (b); i--)
    23 #define REP(i, n) for(int i = 0; i <(n); ++i)
    24 #define SZ(x) ((int)(x).size )
    25 #define ALL(x) (x).begin(), (x.end())
    26 #define MSET(a, x) memset(a, x, sizeof(a))
    27 using namespace std;
    28 
    29 
    30 typedef long long int ll;
    31 typedef pair<int, int> P;
    32 int read() {
    33     int x=0,f=1;
    34     char ch=getchar();
    35     while(ch<'0'||ch>'9') {
    36         if(ch=='-')f=-1;
    37         ch=getchar();
    38     }
    39     while(ch>='0'&&ch<='9') {
    40         x=x*10+ch-'0';
    41         ch=getchar();
    42     }
    43     return x*f;
    44 }
    45 const double pi=3.14159265358979323846264338327950288L;
    46 const double eps=1e-6;
    47 const int mod = 1e9 + 7;
    48 const int INF = 0x3f3f3f3f;
    49 const int MAXN = 50;
    50 const int xi[] = {0, 0, 1, -1};
    51 const int yi[] = {1, -1, 0, 0};
    52 
    53 int N, T;
    54 int a[MAXN][MAXN], cnt, prime[MAXN];
    55 void init() {
    56     for(int i = 2; i <= 51; i++) {
    57         int flag= 1;
    58         for(int j = 2; j*j <= i; j++) {
    59             if(i%j == 0) {
    60                 flag = 0;
    61                 break;
    62             }
    63         }
    64         if(flag) prime[i] = 1;
    65         else prime[i] = 0;
    66     }
    67     memset(a, 0, sizeof(a));
    68     a[0][0] = 1;
    69     for(int i = 1; i <= 25; i++) {
    70         a[i][0] = 1;
    71         for(int j = 1; j <= i; j++) {
    72             a[i][j] = a[i-1][j] + a[i-1][j-1];
    73         }
    74 
    75     }
    76 }
    77 int main() {
    78     //freopen("in.txt", "r", stdin);
    79     init();
    80     int k, s;
    81     scanf("%d%d", &k, &s);
    82     int sum = 0;
    83     for(int i = 2; i <= s; i++) {
    84         int n = s/i;
    85         if(prime[i] && n >= k) {
    86             sum += a[n][k];
    87         }
    88     }
    89     if(s/6>=k)sum -= a[s/6][k];
    90     if(s/10>=k) sum -= a[s/10][k];
    91     if(s/15>=k)sum -= a[s/15][k];
    92     if(s/14>=k)sum -= a[s/14][k];
    93     if(s/21>=k)sum -= a[s/21][k];
    94     if(s/22>=k) sum -= a[s/22][k];
    95     if(sum <= 10000)
    96         printf("%d
    ", sum);
    97     else printf("10000
    ");
    98     return 0;
    99 }
  • 相关阅读:
    Spring jdbcTemplat 写入BLOB数据为空
    Android强制弹出,隐藏输入法.
    Android NDK开发篇(五):Java与原生代码通信(数据操作)
    AIX加入�能够telnet远程连接账号方法
    index of rmvb mp3 rm突破站点入口下载
    C++“窗体”程序设计启蒙(之二)
    C++ Primer 学习笔记_72_面向对象编程 --句柄类与继承[续]
    (a*b)%c 小的技巧
    javascript(arguments)
    Cocos2dx 小技巧(十四)ScrollView实现缩放效果
  • 原文地址:https://www.cnblogs.com/cshg/p/5893340.html
Copyright © 2011-2022 走看看