zoukankan      html  css  js  c++  java
  • 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 ≤ 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

    inputoutput
    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
    ",summ);
    109         }
    110         return 0;
    111 }
    油!油!you@
  • 相关阅读:
    有趣的F-String
    停止使用非版本控制的可执行代码
    Django ORM中,如何使用Count来关联对象的子集数量
    Django Tastypie: 贴士,技巧和故障排除
    我实在不懂Python的Asyncio
    使用Let's Encrypt为网站加入SSL证书
    [debug]记一次竞态更新bug的解决
    我的web聊天之---序章
    我的音乐盒子(nodejs7 + koa2 + vue + vuex + vue-router)
    装饰器 生成器 进阶
  • 原文地址:https://www.cnblogs.com/zzuli2sjy/p/5479767.html
Copyright © 2011-2022 走看看