UVA 10375 Choose and divide
n! 分解素因子 快速幂
ei=[N/pi^1]+ [N/pi^2]+ …… + [N/pi^n] 其中[]为取整
ei 为数 N!中pi 因子的个数;
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std; const int maxn=; int sign[maxn];
int pri[maxn];
int tot; void getpri (){
memset (sign,,sizeof sign);
sign[]=sign[]=;
for (int i=;i<sqrt (maxn+0.5);i++)
if (!sign[i])
for (int j=i*i;j<maxn;j+=i)
sign[j]=;
tot=;
for (int i=;i<maxn;i++)
if (!sign[i])
pri[tot++]=i;
} int e[maxn]; int power (int a,int b){
int ans=;
while (b){
if (b&)
ans*=a;
a*=a;
b>>=;
}
return ans;
} int main (){
getpri ();//cout<<tot<<endl;
int p,q,r,s;
while (~scanf ("%d%d%d%d",&p,&q,&r,&s)/*cin>>p>>q>>r>>s*/){
memset (e,,sizeof e);
int ma=max (p,r);
for (int i=;i<tot;i++){
int temp=pri[i];
while (temp<=ma){
e[i]+=p/temp+s/temp+(r-s)/temp;//if (i==0) cout<<ma<<" ";
e[i]-=r/temp+q/temp+(p-q)/temp;
temp*=pri[i];
}
}
double ans=;
for (int i=;i<tot;i++){
if (e[i]>=)
ans*=1.0*power (pri[i],e[i]);
else ans/=1.0*power (pri[i],-e[i]);//cout<<e[i]<<":"<<pri[i]<<"=";//<<ans<<" ";
}
printf ("%.5f\n",ans);
}
return ;
}
UVA 10375 Choose and divide的更多相关文章
- 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
UVa 10375 Choose and divide 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19601 思路 ...
- UVa 10375 - Choose and divide(唯一分解定理)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 10375 Choose and divide【唯一分解定理】
题意:求C(p,q)/C(r,s),4个数均小于10000,答案不大于10^8 思路:根据答案的范围猜测,不需要使用高精度.根据唯一分解定理,每一个数都可以分解成若干素数相乘.先求出10000以内的所 ...
- UVA 10375 Choose and divide(大数的表示)
紫上给得比较奇怪,其实没有必要用唯一分解定理.我觉得这道题用唯一分解只是为了表示大数. 但是分解得到的幂,累乘的时候如果顺序很奇怪也可能溢出.其实直接边乘边除就好了.因为答案保证不会溢出, 设定一个精 ...
- 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 ...
- 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)结果保留5为小数. 分析: 先用筛法求出10000以内的质数,然后计算每个素数对应的指数,最后再根据指数计算答案. #include <cstd ...
- UVA 10256 The Great Divide(凸包划分)
The Great Divide Input: standard input Output: standard output Time Limit: 8 seconds Memory Limit: 3 ...
随机推荐
- Stripies(POJ 1862 贪心)
Stripies Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 14151 Accepted: 6628 Descrip ...
- GTW likes gt(BC 模拟 or 优先队列)
GTW likes gt Accepts: 54 Submissions: 782 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 13107 ...
- List是线程安全的吗?如果不是该怎么办呢?安全的List对性能的影响有多大呢?
测试条件: 开启2个并行执行任务,往同一个list对象写入值 测试代码: ; static List<int> list = new List<int>(); static v ...
- [转]浅谈C/C++内存泄露及其检测工具
转自:http://www.cnblogs.com/taoxu0903/archive/2007/10/27/939261.html 对于一个c/c++程序员来说,内存泄漏是一个常见的也是令人头疼的问 ...
- mysql-protocol中对编码长度整数型的规则
固定长度整型数值在mysql 协议中的应用之一就是affected row :这个要根据首字节来判断 1.如果首字节小于251;那么首字节就是它要表示的数值. 2.如果首字节等于251;那么它表示的就 ...
- 七、适配器(Adapter)模式--结构模式(Structural Pattern)
适配器模式:把一个类的接口变换成客户端所期待的另一种接口,从而使原本接口不匹配而无法在一起工作的两个类能够在一起工作. 类的 Adapter模式的结构: 类适配器类图: 由图中可以看出,Adaptee ...
- 51单片机实现对24C02进行页写、顺序读取并显示验证
//************************************************************************************* //**程序名称:51单 ...
- 微软的OneDrive研究~
Dropbox 很好,唯一觉得不爽的是只能同步指定的目录.不过被墙之后就不那么方便了,所以改用微软的 Live Mesh,缺点是支持的设备少(仅 PC 和 Mac). https://technet. ...
- 007.androidUI开发进阶(基础--案例) .
1.Dialog有四种,分别是AlertDialog,ProgressDialog,DatePickerDialog,TimePickerDialog 1.1AlertDialog public cl ...
- Java根据年份算出所属的生肖。
一个小程序~ public String getYear(Integer year){ if(year<1900){ return "未知"; } Integer start ...