`

Ural 1091. Tmutarakan Exams

阅读更多
1091. Tmutarakan Exams
Time Limit: 1.0 second
Memory Limit: 16 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

题目大意: 对于k,s<=50,试统计{a1,a2,...,ak|ai<=s and gcd(a1,...ak)>1}的数目。

算法分析:首先按照约数分类{2,3,5,……,s}。

我们会注意到如下事实:如果gcd(x,y)!=1且x<y,那么按照约数x分类的集合A包含按照约数y分类的集合B。如:对s=20,x=2,y=4有:
A={2,4,6,8,10,12,14,16,18,20}
B={4,8,12,16,20}
再如s=20,x=3,y=6有:
A={3,6,9,12,15,18}
B={6,12,18}
显然均有:A包含B
所以由此事实知:我们只需要按照素数分类即可!
但问题又来了,这样分类计数仍有重复!如:
当p=2时,对应的集合为:A={2,4,6,8,10,12,14,16,18,20}
当p=3时,对应的集合为:B={3,6,9,12,15,18}
当k=2时,从A集合中取{6,12}时,从B集合中同时也可以取到{6,12},产生重复!!!咋办呢???
这时容斥原理可以派上用场!对于上面的那种情况只需要再减去按6分类的集合所产生的集合数。
由于s<=50,k>=2,所以只需要考虑这些素数{2,3,5,7,11,13,17,19,23}按这些素数进行分类
以及排除应的情况为6->(2,3),10->(2,5),14->(2,7),22->(2,11),15->(3,5),21->(3,7),其它的不需要考虑。
代码:
#include <iostream>
#include <cstdio>
using namespace std;
const int maxn=60;
int c[maxn][maxn];//存储组合数C(n,m)
void getC()
{//C(n,m)=C(n-1,m)+C(n-1,m-1)
    for(int i=0;i<maxn;i++)
    {
        c[i][0]=1;
        c[i][1]=i;
        c[i][i]=1;
    }
    for(int i=1;i<maxn;i++)
    {
        for(int j=1;j<i;j++)
        {
            int sum=c[i-1][j]+c[i-1][j-1];
            if(sum>10000)   sum=10000;//对于10000的只需存储10000
            c[i][j]=sum;
        }
    }
}
int main()
{
    getC();
    int k,s;
    //while(scanf("%d%d",&k,&s)!=EOF){
    scanf("%d%d",&k,&s);
    int sum=0;
    int prime[9]={2,3,5,7,11,13,17,19,23};
    for(int i=0;i<9;i++)
    {
        if(s/prime[i]<k)    break;
        if(c[s/prime[i]][k]==10000)  {sum=100000;break;}
        sum+=c[s/prime[i]][k];
        //printf("c[%d][%d]=%d\n",s/prime[i],k,c[s/prime[i]][k]);
    }
    if(sum==100000)
    {
        printf("10000\n");
        //continue;
        return 0;
    }
    for(int i=1;i<=4;i++)
    {
        if(s/(prime[i]*2)<k)    break;
        sum-=c[s/(prime[i]*2)][k];
    }
    for(int i=2;i<=3;i++)
    {
        if(s/(prime[i]*3)<k)    break;
        sum-=c[s/(prime[i]*3)][k];
    }
    sum=min(sum,10000);
    printf("%d\n",sum);
    //}
    return 0;
}

分享到:
评论

相关推荐

    Python库 | ural-0.28.0.tar.gz

    资源分类:Python库 所属语言:Python 资源全名:ural-0.28.0.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    Ural URAL 解题思路

    《Ural URAL 解题思路》 在编程竞赛和算法挑战的世界中,Ural University的在线判题系统,简称Ural或URAL,是许多程序员磨炼技能的重要平台。它提供了丰富的算法题目,涵盖数据结构、图论、动态规划、数学等多个...

    acm_ural_1148

    标题 "acm_ural_1148" 指向的是一个 ACM(国际大学生程序设计竞赛)问题,这个问题在 Ural University Online Judge(乌拉尔大学在线评测系统)上编号为 1148。描述中的 "Pascal acm_timus_ural_1148.pas" 表明提供...

    Ural

    "Ural"是一款字体,可能是指一种特定的中文字体或者西文字体设计。在IT领域,字体扮演着至关重要的角色,特别是在图形设计、网页设计、出版印刷以及各种视觉传达中。字体的选择能够极大地影响信息的呈现效果和用户...

    acm_ural_1099

    【标题】"acm_ural_1099" 是一个与编程竞赛相关的主题,通常在ACM(国际大学生程序设计竞赛)或类似的算法比赛中出现。这类问题旨在测试参赛者解决算法问题的能力,通常需要使用一种或多种编程语言来编写解决方案。 ...

    URAL部分测试数据

    URAL部分测试数据是针对Timus Online Judge平台的一个竞赛或练习问题的数据集。Timus Online Judge是一个流行的在线编程竞赛和练习平台,它为参赛者提供了一系列的编程题目,以提升编程技能和算法理解能力。这个数据...

    URAL3D

    "URAL3D"是一个与字体相关的主题,这通常指的是一个特定的三维字体设计或字体库。在计算机领域,字体是用于显示和打印文本的图形表示。它们由一系列字符形状组成,包括字母、数字和标点符号,每个都有其独特的样式和...

    ural部分题解

    "ural部分题解"是一个关于编程竞赛平台Ural(也称为URAL Online Judge或University of Maribor Algorithmic contests)的解题集,由大牛出品。这个资源包含Vol1到Vol3的部分题目解答,虽然不完整,但大约涵盖了200道...

    Ural 1238 源代码

    Ural 1238 源代码 涉及算法(动态规划、贪心、DFS)

    hdu pku ural 题目分类

    HDU、PKU和URAL是三个著名的在线编程竞赛平台,它们为程序员提供了丰富的算法题目,帮助参赛者提升编程技能和算法理解能力。这些平台的题目通常涵盖了基础算法、数据结构、数学逻辑等多个方面,对于准备各类编程竞赛...

    Ural ACM 1000源代码(c++)

    【Ural ACM 1000源代码(c++)】是一个编程竞赛相关的项目,其中包含了使用C++语言编写的源代码,这些代码是为了解决特定的算法问题而设计的。Ural ACM通常指的是乌拉尔大学(University of Ural)举办的算法竞赛,这...

    Ural-开源

    **Ural开源库详解** Ural是一个开源的C++库,专为实现高效、灵活的线性代数计算而设计。这个库的核心特性是利用模板类来表示不同等级的张量,包括标量、向量(等级1)、矩阵(等级2)以及更高阶的张量(如等级3)。...

    ural题解

    《URAL题解》是针对ACM(国际大学生程序设计竞赛)中URAL在线判题系统题库的详尽解析,涵盖了从Vol_I到Vol_III的所有题目。这些文档旨在帮助参赛者理解和解决各种算法问题,提升编程技能,为比赛做好充分准备。 ...

    URAL-PHA

    URAL-PHA是一个与字体相关的主题。在这个压缩包中,我们看到只有一个文件名“2238”,这可能是某种特定字体的文件或者一个包含了多个字体文件的集合。在IT行业中,字体设计是用户界面和视觉传达的重要组成部分,尤其...

    PART II THE URAL-ALTAIC HYPOTHESIS CHAPTER IV. THE URAL-ALTAIC HYPOTHESIS AND TUNGUS MATERIAL (1931年)

    28. The Theoretical Background of the Ural-Altale Hypothesis The hypothesis of common origin of the Altaic languages,and even the Ural-Altaic languages,dates from the first half of the last century....

    ural vol I 题解 by yuhch123 pdf

    ### Ural Volume I 题解 by yuhch123 #### 关于 yuhch123 yuhch123 是一位在 IT 和编程竞赛领域内有着卓越成就的人物,曾在 IOI 2008 中荣获金牌第一名。这份文档是他针对 Ural 编程题库第一卷的解答,对于学习算法...

    oss-js.zip_Hold_qt oss

    This site is created and administrated by the students and graduates of the Ural Federal University. If you want to publish your problems in the archive or hold your own online programming contest, ...

    ural

    "ural"是一个与SCSS相关的项目,SCSS是Sass(Syntactically Awesome Style Sheets)的缩写,是一种预处理器语言,它扩展了CSS,增加了变量、嵌套规则、混合、函数等特性,使CSS编写更加简洁和可维护。在"ural-master...

    线段树题目

    - **URAL 1019**:此题要求计算区间覆盖的颜色,并统计最长相同颜色的区间。这需要在线段树中额外维护一些状态信息,比如每个区间被涂色的次数。 - **ZOJ 2301**:与URAL 1019类似,但这里是针对点进行染色操作。在...

    光学镜头结构

    chieves t he integration of optical and st ruct ural design sof tware. Mainly based on black box compo2 nent met hod , t he development of optical and st ruct ural design sof tware is completed using ...

Global site tag (gtag.js) - Google Analytics