Choose and divide
The binomial coefficient C(m, n) is defined as C(m, n) = m! (m − n)! n! Given four natural numbers p, q, r, and s, compute the the result of dividing C(p, q) by C(r, s). Input Input consists of a sequence of lines. Each line contains four non-negative integer numbers giving values for p, q, r, and s, respectively, separated by a single space. All the numbers will be smaller than 10,000 with p ≥ q and r ≥ s. Output For each line of input, print a single line containing a real number with 5 digits of precision in the fraction, giving the number as described above. You may assume the result is not greater than 100,000,000.
Sample Input
10 5 14 9 93 45 84 59 145 95 143 92 995 487 996 488 2000 1000 1999 999 9998 4999 9996 4998
Sample Outpu
t 0.12587 505606.46055 1.28223 0.48996 2.00000 3.99960
唯一分解定理应用
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<deque>
#include<iomanip>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<memory>
#include<list>
#include<string>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MAXN 10009
#define L 31
#define INF 1000000009
#define eps 0.00000001
/*
唯一分解定理 应用
*/
int prime[MAXN], e[MAXN];
void getprime()
{
memset(prime, false, sizeof(prime));
for (int i = ; i <= MAXN; i++)
{
if (!prime[i])
prime[++prime[]] = i;
for (int j = ; j <= prime[] && prime[j] <= MAXN / i; j++)
{
prime[prime[j] * i] = ;
if (i%prime[j] == ) break;
}
}
}
void add_interger(int n, int d)
{
for (int i = ; i <= prime[]; i++)
{
while (n%prime[i] == )
{
n /= prime[i];
e[i] += d;
}
if (n == ) break;
}
}
void add_factorial(int n, int d)
{
for (int i = ; i <= n; i++)
add_interger(i, d);
}
int main()
{
getprime();
int p, q, r, s;
while (cin >> p >> q >> r >> s)
{
memset(e, , sizeof(e));
add_factorial(p, );
add_factorial(q, -);
add_factorial(p - q, -);
add_factorial(r, -);
add_factorial(s, );
add_factorial(r - s, );
double ans = ;
for (int i = ; i <= prime[]; i++)
ans *= pow(prime[i], e[i]);
printf("%.5lf\n", ans);
}
return ;
}
Choose and divide的更多相关文章
- UVA - 10375 Choose and divide[唯一分解定理]
UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- uva10375 Choose and Divide(唯一分解定理)
uva10375 Choose and Divide(唯一分解定理) 题意: 已知C(m,n)=m! / (n!*(m-n!)),输入整数p,q,r,s(p>=q,r>=s,p,q,r,s ...
- 【暑假】[数学]UVa 10375 Choose and divide
UVa 10375 Choose and divide 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19601 思路 ...
- UVA10375 Choose and divide 质因数分解
质因数分解: Choose and divide Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %l ...
- UVA 10375 Choose and divide【唯一分解定理】
题意:求C(p,q)/C(r,s),4个数均小于10000,答案不大于10^8 思路:根据答案的范围猜测,不需要使用高精度.根据唯一分解定理,每一个数都可以分解成若干素数相乘.先求出10000以内的所 ...
- uva10375 Choose and divide
唯一分解定理. 挨个记录下每个质数的指数. #include<cstdio> #include<algorithm> #include<cstring> #incl ...
- UVa 10375 (唯一分解定理) Choose and divide
题意: 求组合数C(p, q) / C(r, s)结果保留5为小数. 分析: 先用筛法求出10000以内的质数,然后计算每个素数对应的指数,最后再根据指数计算答案. #include <cstd ...
- UVA 10375 Choose and divide
n! 分解素因子 快速幂 ei=[N/pi^1]+ [N/pi^2]+ …… + [N/pi^n] 其中[]为取整 ei 为数 N!中pi 因子的个数: #include <iostream& ...
- UVa 10375 - Choose and divide(唯一分解定理)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- Choose and divide(唯一分解定理)
首先说一下什么是唯一分解定理 唯一分解定理:任何一个大于1的自然数N,如果N不是质数,那么N可以分解成有限个素数的乘积:例:N=(p1^a1)*(p2^a2)*(p3^a3)......其中p1< ...
随机推荐
- Apache Kafka官方文档翻译(原创)
Apache Kafka是一个分布式流平台.准确的说是什么意思呢?我们认为流平台具有三种关键能力: 1.让你对数据流进行发布订阅.因此他很像一个消息队列和企业级消息系统. 2.让你以高容错的方式存储数 ...
- SQL函数类的操作,增加,查询
数据库连接: 表的创建: 创建连接对象,命令对象类: 添加函数: 查询函数类: List<>集合,里面专门放对象 函数主体: 查询: foreach只能修改,不能添加删除
- java简单打印金字塔(案例)
学习编程语言,打印简单的金字塔是基础的案例,在这里就简单的写了个案例,希望能帮助到各位 代码 效果 class kinTa{ public static void main(String[] ...
- Spark性能优化指南-高级篇(spark shuffle)
Spark性能优化指南-高级篇(spark shuffle) 非常好的讲解
- WCF学习笔记(1)-一个完整的例子
一.开发环境 IDE:VS2013 OS:Win10 IIS:IIS 10 二.开发流程 1.项目结构 2.添加一个WCF程序 3.删除系统自动生成的两个文件IService1.cs和Service1 ...
- Python代码搜索并下载酷狗音乐
运行环境: Python3.5+Pycharm 实例代码: import requests,re keyword = input("请输入想要听的歌曲:") url = " ...
- Android 网络图片查看器与网页源码查看器
在AndroidManifest.xml里面先添加访问网络的权限: <uses-permission android:name="android.permission.INTERNET ...
- 【C++】智能指针简述(二):auto_ptr
首先,我要声明auto_ptr是一个坑!auto_ptr是一个坑!auto_ptr是一个坑!重要的事情说三遍!!! 通过上文,我们知道智能指针通过对象管理指针,在构造对象时完成资源的分配及初始化,在析 ...
- react Native环境 搭建
react Native的优点:跨平台 低投入高回报 性能高 支持动态更新.一才两用(ios和Android) 开发成本第 代码复用率高.windows环境搭建react Native开发环境1.安装 ...
- jsp学习笔记 - 内置对象 config
1.将页面保存在 WEB-INF文件夹下是最安全的,一般不可见 可以通过映射路径来进行访问 2.通过config对象可以取得初始化的配置参数 String dbDriver = config.getI ...