http://acm.timus.ru/problem.aspx?

space=1&num=1091

从1~s中选出k个数,使得k个数的最大公约数大于1,问这种取法有多少种。

(2<=k <= s<=50)

同素数四元组问题类似,能够參考http://blog.csdn.net/u013081425/article/details/40653895

仅仅只是这里是选出k个。不是4个。

#include <stdio.h>
#include <iostream>
#include <map>
#include <set>
#include <bitset>
#include <list>
#include <stack>
#include <vector>
#include <math.h>
#include <string.h>
#include <queue>
#include <string>
#include <stdlib.h>
#include <algorithm>
#define LL __int64
//#define LL long long
#define eps 1e-9
#define PI acos(-1.0)
using namespace std;
const int maxn = 100010; int k,s;
int num[55];
int prime[] = {15,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
int cnt[55];
LL c[55][55]; void init()
{
memset(c,0,sizeof(c));
for(int i = 1; i <= 25; i++)
{
for(int j = 0; j <= i; j++)
{
if(j == 0 || j == i)
c[i][j] = 1;
else if(j == 1)
c[i][j] = i;
else
c[i][j] = c[i-1][j-1] + c[i-1][j];
}
}
} void dfs(int st, int val, int num)
{
if(val > 50) return;
cnt[val] = num&1 ? 1 : -1;
for(int i = st; i <= prime[0]; i++)
{
if(prime[i]*val > 50)
break;
dfs(i+1,val*prime[i],num+1);
}
} int main()
{
init();
memset(cnt,0,sizeof(cnt));
dfs(1,1,0);
while(~scanf("%d %d",&k,&s))
{
for(int d = 2; d <= s; d++)
{
num[d] = s/d;
} LL ans = 0; for(int d = 2; d <= s; d++)
{
if(num[d] < k)
break;
if(cnt[d])
{
ans += cnt[d]*c[num[d]][k];
}
}
if(ans >= 10000)
printf("10000\n");
else
printf("%I64d\n",ans);
}
return 0;
}

ural 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. F - Tmutarakan Exams URAL - 1091 -莫比乌斯函数-容斥 or DP计数

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

  3. Ural 1091 Tmutarakan Exams

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

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

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

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

  6. URAL1091. Tmutarakan Exams(容斥)

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

  7. 1091. Tmutarakan Exams

    1091. Tmutarakan Exams Time limit: 1.0 secondMemory limit: 64 MB University of New Tmutarakan trains ...

  8. 容斥原理--计算并集的元素个数 URAL 1091

    在计数时,必须注意没有重复,没有遗漏.为了使重叠部分不被重复计算,人们研究出一种新的计数方法,这种方法的基本思想是:先不考虑重叠的情况,把包含于某内容中的所有对象的数目先计算出来,然后再把计数时重复计 ...

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

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

随机推荐

  1. ReSharper修改命名风格

    默认情况下,ReSharper会建议你全局变量命名使用下划线开头,且第一个字母小写.否则,会给你标记出来,如下: 但我个人不喜欢这种风格,一般使用首字母大写且不带下划线,可以通过配置来调整:ReSha ...

  2. 【转】开发者可以使用Docker做什么?

    有些开发者可能还是不明白 Docker 对自己到底有多大的用处,因此翻译 Docker 个人用例 这篇文章中来介绍 Docker 在普通开发者开发过程中的用例. Docker 如今赢得了许多关注,很多 ...

  3. Linux中查看系统版本的方法

    一.Linux系统中,XShell连接进去之后,查看系统版本的方法如下: 1.查找release文件 find /etc/ -name *-release 例如: 或者 2.查看release文件 c ...

  4. 008-Go 关于字符串拼接

    如果是少量小文本拼接,用 “+” 如果是大量小文本拼接,用 strings.Join 如果是大量大文本拼接,用 bytes.Buffer package main import( "fmt& ...

  5. vuejs组件交互 - 03 - vuex状态管理实现组件交互

    组件交互模式的使用场景 简单应用直接使用props down,event up的模式就可以了 小型应用使用事件中心模式即可 中大型应用使用vuex的状态管理模式 vuex 包含要管理的应用数据和更新数 ...

  6. ViewRoot,DecorView,MeasureSpec和View的工作原理——Android开发艺术探索笔记

    原文链接 http://sparkyuan.me/ 转载请注明出处 View的绘制流程是从ViewRoot的performTraversals方法開始的.它经过measure.layout和draw三 ...

  7. C# new和初始化

    虽然知道使用new可以创建对象,但一直不是很理解初始化和new等知识的具体. 通过8个问题和需求,了解相关知识. 了解问题和需求 1.new 的三个步骤 2.初始化是什么意思. 3.变量声明后和变量赋 ...

  8. Percona-XtraBackup系列二:备份恢复

    #在备份较大数据量的时候推荐xtrabackup,这个工具比mysqldump要快很多. 一.Xtrabackup介绍 1,Xtrabackup是什么 Xtrabackup是一个对InnoDB做数据备 ...

  9. 行内元素有哪些?块级元素有哪些? 空(void)元素有那些?

    行内元素:a.b.span.img.input.strong.select.label.em.button.textarea块级元素:div.ul.li.dl.dt.dd.p.h1-h6.blockq ...

  10. Java之所有对象的公用方法>8.Obey the general contract when overriding equals

    Overriding the equals method seems simple, but there are many ways to get it wrong, and consequences ...