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的更多相关文章

  1. UVA - 10375 Choose and divide[唯一分解定理]

    UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  2. 【暑假】[数学]UVa 10375 Choose and divide

    UVa 10375 Choose and divide 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19601 思路 ...

  3. UVa 10375 - Choose and divide(唯一分解定理)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  4. UVA 10375 Choose and divide【唯一分解定理】

    题意:求C(p,q)/C(r,s),4个数均小于10000,答案不大于10^8 思路:根据答案的范围猜测,不需要使用高精度.根据唯一分解定理,每一个数都可以分解成若干素数相乘.先求出10000以内的所 ...

  5. UVA 10375 Choose and divide(大数的表示)

    紫上给得比较奇怪,其实没有必要用唯一分解定理.我觉得这道题用唯一分解只是为了表示大数. 但是分解得到的幂,累乘的时候如果顺序很奇怪也可能溢出.其实直接边乘边除就好了.因为答案保证不会溢出, 设定一个精 ...

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

  7. UVA10375 Choose and divide 质因数分解

    质因数分解: Choose and divide Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %l ...

  8. UVa 10375 (唯一分解定理) Choose and divide

    题意: 求组合数C(p, q) / C(r, s)结果保留5为小数. 分析: 先用筛法求出10000以内的质数,然后计算每个素数对应的指数,最后再根据指数计算答案. #include <cstd ...

  9. UVA 10256 The Great Divide(凸包划分)

    The Great Divide Input: standard input Output: standard output Time Limit: 8 seconds Memory Limit: 3 ...

随机推荐

  1. PHP判断访客是否移动端浏览器访问

    今天要给大家分享一段PHP代码,该代码的功能是用来判断访客是否移动端浏览器访问,该功能的实现思路是通过HTTP_X_WAP_PROFILE. HTTP_VIA.HTTP_USER_AGENT等信息来判 ...

  2. flash播放器遮挡页面中元素问题解决

    今天在做一个包含Flash播放器的页面弹出效果时发现Flash播放器总是跑到页面最上层,发现这个问题与Flash的”wmode”属性有关,至于该元素详细此处不做记录,解决办法如下: IE:加入参数:& ...

  3. Roads in Berland(图论)

    Description There are n cities numbered from 1 to n in Berland. Some of them are connected by two-wa ...

  4. 【转】arm交叉编译器gnueabi、none-eabi、arm-eabi、gnueabihf、gnueabi区别

    原文网址:http://www.veryarm.com/296.html 命名规则 交叉编译工具链的命名规则为:arch [-vendor] [-os] [-(gnu)eabi] arch - 体系架 ...

  5. Letter Combinations of a Phone Number 解答

    Question Given a digit string, return all possible letter combinations that the number could represe ...

  6. 【CF 676B Pyramid of Glasses】模拟,递归

    题目链接:http://codeforces.com/problemset/problem/676/B 题意:一个n层的平面酒杯金字塔,如图,每个杯子的容量相同.现在往最顶部的一个杯子倒 t 杯酒,求 ...

  7. java_IO流之 NIO

    NIO 定义 即新IO,在JDK1.4的java.nio.*包中引入,其目的在于提高速度. 在Java1.4之前的I/O系统中,提供的都是面向流的I/O系统,系统一次一个字节地处理数据,一个输入流产生 ...

  8. FreeMarker的模板文件语法

    FreeMarker的模板文件并不比HTML页面复杂多少,FreeMarker模板文件主要由如下4个部分组成: 1,文本:直接输出的部分 2,注释:<#-- ... -->格式部分,不会输 ...

  9. 【剑指Offer学习】【面试题60:把二叉树打印出多行】

    题目:从上到下按层打印二叉树,同一层的结点按从左到右的顺序打印,每一层打印一行. 解题思路 用一个队列来保存将要打印的结点.为了把二叉树的每一行单独打印到一行里,我们须要两个变量:一个变量表示在当前的 ...

  10. php接口数据加密、解密、验证签名代码实例

    php接口数据加密.解密.验证签名 代码非常easy,这里就不多废话了,直接奉上代码 <?php /** * 数据加密.解密.验证签名 * @edit http://www.lai18.com ...