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 ...
随机推荐
- opencv for python
opencv显示图像: # -*- coding: UTF-8 -*- import numpy as np import cv2 from matplotlib import pyplot as p ...
- information_schema.key_column_usage 学习
information_schema.key_column_usage 表可以查看索引列上的约束: 1.information_schema.key_column_usage 的常用列: 1.cons ...
- C++----练习--string 从文件中一个一个单词的读直到文件尾
从文件中读取单词.并每行显示一个: 1. #include<iostream> #include<string> #include<vector> int main ...
- C++----练习--引用头文件
1.创建头文件和源文件 touch /tmp/tools.h touch /tmp/main.cpp 2.各文件的内容如下: tools.h #include<iostream> void ...
- 常用两种数据交换格式之XML和JSON的比较
目前,在web开发领域,主要的数据交换格式有XML和JSON,对于XML相信每一个web developer都不会感到陌生: 相比之下,JSON可能对于一些新步入开发领域的新手会感到有些陌生,也可能你 ...
- 理解 backbone.js 中的 bind 和 bindAll 方法,关于如何在方法中指定其中的 this,包含apply方法的说明[转载]
转载自:http://gxxsite.com/content/view/id/132.html 在backbone.js的学习过程中,被bind和bindAll弄得有点晕,这里包括underscore ...
- [ArcGIS Engine]栅格数据处理 RasterDataset RasterLayer Raster RasterBandCollection
原文 http://www.cnblogs.com/zoe-j/archive/2012/03/22/2412403.html 1.由RasterLayer 得到RasterDataset IRast ...
- 51 EEPROM操作模板
各个型号容量及扇区请查datasheet #include <reg52.h> #include "intrins.h" typedef unsigned char b ...
- relative与absolute相结合
relative会把别人挤下去, absolute会跑偏. 两者结合就会很好的解决问题. <span class='pic_selected' style='position:relative; ...
- HDOJ-1014 Uniform Generator
http://acm.hdu.edu.cn/showproblem.php?pid=1014 给出式子seed(x+1) = [seed(x) + STEP] % MOD seed初始为0,给出STE ...