UVa 10375 (唯一分解定理) Choose and divide
题意:
求组合数C(p, q) / C(r, s)结果保留5为小数。
分析:
先用筛法求出10000以内的质数,然后计算每个素数对应的指数,最后再根据指数计算答案。
#include <cstdio>
#include <cmath>
#include <cstring> const int maxn = ;
int pri[maxn], cnt, e[maxn]; //e记录每个素数的质数
bool vis[maxn + ]; void add_interger(int n, int d) //乘以n的d次幂
{
for(int i = ; i < cnt; ++i)
{
while(n % pri[i] == )
{
n /= pri[i];
e[i] += d;
}
if(n == ) return;
}
} void add_factorial(int n, int d) //乘以(n!)的d次幂
{
for(int i = ; i <= n; ++i)
add_interger(i, d);
} int main()
{
//freopen("10375in.txt", "r", stdin); int m = sqrt(maxn + 0.5);
for(int i = ; i <= m; ++i) if(!vis[i])
for(int j = i*i; j <= maxn; j += i) vis[j] = true;
cnt = ;
for(int i = ; i < maxn; ++i) if(!vis[i]) pri[cnt++] = i;
//for(int i = 0; i < 10; ++i) printf("%d\n", pri[i]); int p, q, r, s;
while(scanf("%d%d%d%d", &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 = 1.0;
for(int i = ; i < cnt; ++i)
ans *= pow(pri[i], e[i]); printf("%.5f\n", ans);
} return ;
}
代码君
UVa 10375 (唯一分解定理) Choose and divide的更多相关文章
- UVA - 10780 唯一分解定理
白书P171 对m,n!分解,质因子指数取min #include<iostream> #include<algorithm> #include<cstdio> # ...
- UVa 1635 (唯一分解定理) Irrelevant Elements
经过紫书的分析,已经将问题转化为求组合数C(n-1, 0)~C(n-1, n-1)中能够被m整除的个数,并输出编号(这n个数的编号从1开始) 首先将m分解质因数,然后记录下每个质因子对应的指数. 由组 ...
- UVA 10791 -唯一分解定理的应用
#include<iostream> #include<stdio.h> #include<algorithm> #include<string.h> ...
- UVA - 11388 唯一分解定理
题意:给出G和L,求最小的a使得gcd(a,b)=G,lcm(a,b)=L 显然a>=G,所以a取G,b要满足质因子质数为L的同次数,b取L //此处应有代码
- UVA - 10375 Choose and divide[唯一分解定理]
UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- UVA 10375 Choose and divide【唯一分解定理】
题意:求C(p,q)/C(r,s),4个数均小于10000,答案不大于10^8 思路:根据答案的范围猜测,不需要使用高精度.根据唯一分解定理,每一个数都可以分解成若干素数相乘.先求出10000以内的所 ...
- 【暑假】[数学]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(唯一分解定理)
uva10375 Choose and Divide(唯一分解定理) 题意: 已知C(m,n)=m! / (n!*(m-n!)),输入整数p,q,r,s(p>=q,r>=s,p,q,r,s ...
- Choose and divide(唯一分解定理)
首先说一下什么是唯一分解定理 唯一分解定理:任何一个大于1的自然数N,如果N不是质数,那么N可以分解成有限个素数的乘积:例:N=(p1^a1)*(p2^a2)*(p3^a3)......其中p1< ...
随机推荐
- How to avoid C# console applications from closing automatically.
One way is to interop it with msvcrt.dll You can pinvoke this C function into your C# application. T ...
- tomcat内存溢出,设置
tomcat/bin/catalina.bat里找到echo Using CATALINA_BASE: "%CATALINA_BASE%" ,在上方设置: set JAV ...
- 3139:[HNOI2013]比赛 - BZOJ
题目描述 Description 沫沫非常喜欢看足球赛,但因为沉迷于射箭游戏,错过了最近的一次足球联赛.此次联赛共N只队伍参加,比赛规则如下: (1) 每两支球队之间踢一场比赛. (2) 若平局,两支 ...
- CSS:在input、pre中左边加上一个图标(一行和多行)
前言 接触过EasyUI的朋友都知道其警告框就是左边有个三角警告图标,此文所做的效果正是这样.此外,还将示例多行的做法. 一.在input左边加上一个图标(一行) 注:left center定义了图标 ...
- 解决ORA-00020错误
解决ORA-00020错误 分类: Oracle2009-05-13 17:26 3398人阅读 评论(0) 收藏 举报 数据库sessionoraclesql服务器object 项目上使用的Orac ...
- CPU/ABI显示No system images installed for this target的解决方案
CPU/ABI显示No system images installed for this target的解决方案 手动下载image http://www.androiddevtools.cn/ SD ...
- wireshark: there are no interfaces on which a capture can be done
权限问题,简单的直接sudo就行. 更安全的做法是: # chmod 4755 /usr/bin/dumpcap dumpcap的所在目录可用whereis命令查看.
- Ios 弹框 MJPopup,KxMenu
IOS 弹框 如果直接弹出一个自定义的视图 可以选用第三方: MJPopup 弹出: if(!bandview) { bandview=[[[NSBundle mainBundle]loadNibNa ...
- JavaWeb项目开发案例精粹-第2章投票系统-005实体层
1. package com.sanqing.bean; /** * * 投票选项类 * */ public class VoteOption { private int voteOptionID; ...
- Photoshop:建议设置
一.新建文档设置: 二.对齐设置 菜单->视图->对齐->全部 使用图层.形状等操作时自动对齐网格,画矢量图不怕模糊边缘,确保每个像素保持清晰. 三.首选项设置 关掉"启用 ...