唯一分解定理。

挨个记录下每个质数的指数。

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
const int maxn = 100000 + 10;
typedef long long LL; double ans;
int p,q,s,t;
bool mark[maxn];
int prime[maxn],cnt;
int f[maxn]; void get_prime() {
for(int i=2;i<=10000;i++) {
if(!mark[i]) prime[++cnt]=i;
for(int j=1;j<=cnt;j++) {
int t=prime[j]*i;
if(t>10000) break;
mark[t]=1;
if(i%prime[j]==0) break;
}
}
} inline void work(int n,int d) {
for(int i=1;i<=cnt;i++) if(!(n%prime[i])) {
while(!(n%prime[i])) {
n/=prime[i];
f[i]+=d;
}
if(n==1) break;
}
} inline void add(int m,int n,int d) {
for(int i=m;i<=n;i++) work(i,d);
} int main() {
get_prime();
while(scanf("%d%d%d%d",&p,&q,&s,&t)==4) {
memset(f,0,sizeof(f));
add(q+1,p,1);
add(1,p-q,-1);
add(t+1,s,-1);
add(1,s-t,1);
ans=1;
//for(int i=1;i<=cnt;i++) if(f[i]) {
// if(f[i]>0) for(int j=1;j<=f[i];j++) ans*=prime[i];
// else for(int j=1;j<=-f[i];j++) ans/=prime[i];
// }
for(int i=1;i<=cnt;i++) if(f[i]) ans*=pow(prime[i],f[i]);
printf("%.5lf\n",ans);
}
return 0;
}

uva10375 Choose and divide的更多相关文章

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

  2. UVA10375 Choose and divide 质因数分解

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

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

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

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

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

  5. UVA10375 选择与除法 Choose and divide 题解

    题目链接: https://www.luogu.org/problemnew/show/UVA10375 分析: 这道题可以用唯一分解定理来做. 什么是唯一分解定理?百度即可,这里也简介一下. 对于任 ...

  6. Choose and divide(唯一分解定理)

    首先说一下什么是唯一分解定理 唯一分解定理:任何一个大于1的自然数N,如果N不是质数,那么N可以分解成有限个素数的乘积:例:N=(p1^a1)*(p2^a2)*(p3^a3)......其中p1< ...

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

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

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

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

  9. UVA 10375 Choose and divide

    n! 分解素因子 快速幂 ei=[N/pi^1]+ [N/pi^2]+ …… + [N/pi^n]  其中[]为取整 ei 为数 N!中pi 因子的个数: #include <iostream& ...

随机推荐

  1. mysql获取日期(将时间戳转换成短日期格式)

    且看如下: '; 结果: +-------------------------------------+---------------------+ | date_format(create_time ...

  2. 生鲜电商的O2O之道

  3. mongodb 的安装历程

    mongo 安装历程 mongo的安装方法有千万种,只有一种让我觉得还不错,说说安装过程中的一点心德. 方法一:源码安装,千万别用这种方法,尼马我用虚拟机编译了一下午,竟然没有编译完,强制关机,第二天 ...

  4. ios开发之数据存取1-SQLite

    iOS开发中常用的数据存取方式有: XML属性列表-PList NSKeyedArchiver 归档 Preference-偏好设置 SQLite3 Core Data-以面向对象的方式操作数据库SQ ...

  5. Introduction to Deep Neural Networks

    Introduction to Deep Neural Networks Neural networks are a set of algorithms, modeled loosely after ...

  6. uva 10160

    一开始写的代码加上各种剪枝后还是超时, 然后看了一下状态压缩后过了,两个代码的具体思想是一样的,状态压缩后可以大大提升性能 #include <cstdio> #include <c ...

  7. 全球说:要给 OneAlert 点100个赞

    客户背景 「全球说」 Talkmate,是北京酷语时代教育科技有限公司(酷语科技)旗下产品,酷语科技是一家诞生于中国的语言技术公司,致力于为全球用户提供一个全新的多语言学习和社交网络平台 . 全球说是 ...

  8. HBase入门

    /×××××××××××××××××××××××××××××××××××××××××/ Author:xxx0624 HomePage:http://www.cnblogs.com/xxx0624/ ...

  9. lintcode:最大子正方形

    题目: Maximal Square Given a 2D binary matrix filled with 0's and 1's, find the largest square contain ...

  10. [z]CAP原理和BASE思想

    分布式领域CAP理论,Consistency(一致性), 数据一致更新,所有数据变动都是同步的Availability(可用性), 好的响应性能Partition tolerance(分区容错性) 可 ...