唯一分解定理。

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

#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. 实用项目管理前台框架:EasyUI,ExtJs

    EasyUI项目管理框架,如图: 项目名称:微信管理平台 项目地址:http://www.cnblogs.com/hanyinglong/p/3236966.html#3007557 托管地址:htt ...

  2. 生鲜电商的O2O之道

  3. C# - (0x80040154): Retrieving the COM class factory for component with CLSID {877AA945-1CB2-411C-ACD7-C70B1F9E2E32} failed

    1. Exeption Error: System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM clas ...

  4. C# testJsonAsXMLNodeAttribute - XML& json & Collections - XmlNode, XmlElement, XmlAttribute,Dictionary,List

    testJsonAsXMLNodeAttribute using Newtonsoft.Json; using System; using System.Collections.Generic; us ...

  5. 清橙A1363. 水位 - 清华大学2012年信息学优秀高中学子夏令营

    问题描述 有一个正方形的地区,该地区特点鲜明:如果把它等分为N×N个小正方形格子的话,在每个格子内的任意地点的地表高度是相同的,并且是一个0到M之间的整数.正方形地区的外部被无限高的边界包围. 该地区 ...

  6. hdu1116

    http://acm.hdu.edu.cn/showproblem.php?pid=1116 #include<stdio.h> #include<math.h> #inclu ...

  7. lintcode:Matrix Zigzag Traversal 矩阵的之字型遍历

    题目: 矩阵的之字型遍历 给你一个包含 m x n 个元素的矩阵 (m 行, n 列), 求该矩阵的之字型遍历. 样例 对于如下矩阵: [ [1, 2, 3, 4], [5, 6, 7, 8], [9 ...

  8. lintcode:Find the Connected Component in the Undirected Graph 找出无向图汇总的相连要素

    题目: 找出无向图汇总的相连要素 请找出无向图中相连要素的个数. 图中的每个节点包含其邻居的 1 个标签和 1 个列表.(一个无向图的相连节点(或节点)是一个子图,其中任意两个顶点通过路径相连,且不与 ...

  9. lintcode:Remove Element 删除元素

    题目: 删除元素 给定一个数组和一个值,在原地删除与值相同的数字,返回新数组的长度. 元素的顺序可以改变,并且对新的数组不会有影响.  样例 给出一个数组 [0,4,4,0,0,2,4,4],和值 4 ...

  10. spring中的aware接口

    1.实现了相应的aware接口,这个类就获取了相应的资源. 2.spring中有很多aware接口,包括applicationContextAware接口,和BeanNameAware接口. 实现了这 ...