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 ...
随机推荐
- Ecstore中如何调用发起Ajax请求
Ecstore的JS框架使用了mootools,所以ajax调用也使用mootools中的Request组件. 语法: var myRequest = new Request([options]); ...
- 一级域名301重定向到www二级域名
301重定向有利于百度的搜索 例如一个域名 www.test.com如果不做设置会产生4个网址, (1)test.com(2)www.test.com(3)test.com/default.html( ...
- 使用jekyll主题
github上面有很多基于jekyll的主题 https://github.com/theme4jekyll 使用起来也非常方便.直接clone到本地 这些主题,包括了很多模板,在新建博客的时候可以在 ...
- Python学习(六) Python数据类型:字典(重要)
字典dict: 字典其实就相当于java里面的Map,用来存储键值对的.其中存储的数据时无序的. 假如有这样的数据: t1=['name','age','sex'] t2=['tom',30,'mal ...
- Django的痛点
如果一个html里面写了多个<a href = A.html > ,启动A.html也有这个<a herf = B.xml> 这个时候Django怎么访问这些url?
- jquery.sortable.js源代码解读
/* * HTML5 Sortable jQuery Plugin * http://farhadi.ir/projects/html5sortable * * Copyright 2012, Ali ...
- USB class总结
以下是总结的USB的类,不同的USB类,主机询问的描述符格式和内容都不一样,具体的descriptor的内容可以查看 USB spec(http://www.usb.org/home/),如HID的s ...
- SQL Server索引语法 <第四篇>
从CREATE开始 通过显式的CREATE INDEX命令 在创建约束时作为隐含的对象 随约束创建的隐含索引 当向表中添加如下两种约束之一时,就会创建隐含索引. 主键约束(聚集索引) 唯一约束(唯一索 ...
- CentOS安装错误:no default or ui configuration
靠,以后再也不用浏览器自带的下载工具下载镜像文件了,原来是下载的不完整,但是显示完全下载完毕了,真特么误导人.文件的checksum不对. references: https://www.centos ...
- ajax jquery return没有返回值
错误写法: function editdivisionmember(division_id,users_id){ $.ajax({ type:"POST", url:"/ ...