fzu-1753 Another Easy Problem-高速求N!多少个月p
它计算每个C(N,M)什么号码乘以像。。。。
#include <iostream>
#include<stdio.h>
#include<vector>
#include<queue>
#include<stack>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define LL long long
#define lcm(a,b) (a*b/gcd(a,b))
//O(n)求素数,1-n的欧拉数
#define N 110000
#define PM 11000
struct math_use
{
int phi[N];
vector<int>prime;
void mkphilist()
{
int i,j;
phi[1]=1;
for(i=2; i<N; ++i)
if(!phi[i])
for(j=i; j<N; j+=i)
{
if(!phi[j])
phi[j]=j;
phi[j]-=phi[j]/i;
}
prime.clear();
for(int i=2; i<N; i++)
{
if(phi[i]==i-1)prime.push_back(i);
}
}
//N!中素因子P的个数
//复杂度p^x约等于n!,复杂度为x
LL nump(LL n,LL p)
{
LL cnt=0;
while (n)
{
cnt+=n/p;
n/=p;
}
return cnt;
}
} M;
int num[PM];
LL mul(LL a,LL b)
{
LL ret=1;
LL tmp=a;
while(b)
{
//基数存在
if(b&0x1) ret=ret*tmp;
tmp=tmp*tmp;
b>>=1;
}
return ret;
}
int pp;
void dos(LL n,LL m)
{
int len=M.prime.size();
int x=0;
int ks=-1;
for(int i=0; i<=pp; i++)
{
x=M.nump(n,M.prime[i])-M.nump(m,M.prime[i])-M.nump(n-m,M.prime[i]);
num[i]=min(num[i],x);
if(x!=0)ks=max(ks,i);
}
pp=min(pp,ks);
}
int main()
{
LL n,m;
int t;
M.mkphilist();
while(~scanf("%d",&t))
{
for(int i=0; i<PM; i++)num[i]=99999999;
pp=M.prime.size()-1;
for(int i=1; i<=t; i++)
{
scanf("%I64d%I64d",&n,&m);
dos(n,m);
}
int len=M.prime.size();
LL ans=1;
for(int i=0; i<=pp; i++)
{
ans=ans*mul(M.prime[i],num[i]);
}
cout<<ans<<endl;
}
return 0;
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。
fzu-1753 Another Easy Problem-高速求N!多少个月p的更多相关文章
- fzu 1753 Another Easy Problem
本题题意为求 t (t<150) 个 c (n,m) (1<=m<=n<=100000)的最大公因子: 本题的难点为优化.主要有两个优化重点.一是每次对单个素因子进行处理,优 ...
- POJ 2826 An Easy Problem?!
An Easy Problem?! Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7837 Accepted: 1145 ...
- HDU 5475 An easy problem 线段树
An easy problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...
- [POJ] 2453 An Easy Problem [位运算]
An Easy Problem Description As we known, data stored in the computers is in binary form. The probl ...
- Another Easy Problem fzu1753
Another Easy Problem Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u ...
- zzuli 1815: easy problem 打表
1815: easy problem Time Limit: 1 Sec Memory Limit: 128 MB Submit: 243 Solved: 108 SubmitStatusWeb ...
- hdu2601 An easy problem(数学)
题目意思: http://acm.hdu.edu.cn/showproblem.php? pid=2601 给出一个数N,求N=i*j+i+j一共同拥有多少种方案. 题目分析: 此题直接暴力模拟就可以 ...
- UESTC 1591 An easy problem A【线段树点更新裸题】
An easy problem A Time Limit: 2000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others ...
- An Easy Problem?!(细节题,要把所有情况考虑到)
http://poj.org/problem?id=2826 An Easy Problem?! Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
- POJ 2826 An Easy Problem?![线段]
An Easy Problem?! Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12970 Accepted: 199 ...
随机推荐
- svn hook pre-commit
#!/bin/bashexport LANG="zh_CN.UTF-8" #确保中文日志显示正常,便于统计日志REPOS="$1"TXN="$2&qu ...
- ios app初始化和数据迁移的设计思路
整体思路 一般app启动之后,都有一个初始化的过程. 此外兴许app升级,还须要考虑数据迁移.所以初始化和数据迁移的框架.在初期的版本号就要考虑好 总结一下我们的app採取的方案: 1.在持久化的文件 ...
- SQLServer重建索引
Use [数据库名称]Go DECLARE @DBCCString NVARCHAR(1000)DECLARE @TableName VARCHAR(100)DECLARE Cur_Index CUR ...
- Chrome谷歌浏览器web前端开发好用插件(自己用)备忘
Chrome谷歌浏览器web前端开发好用插件(自己用)备忘 一.总结 英语好一点的话要什么工具就直接去Chrome插件里面找非常方便. 二.测试题-简答题 1.Chrome修改页面字符集是什么? 解答 ...
- 前端工具WebStorm好在哪里?(带详细破解教程)
前端工具WebStorm好在哪里?(带详细破解教程) 一.总结 1.WebStorm对html特别是HTML5和JS的智能提示简直堪称大神. 2.WebStorm足够的轻量级. 3.WebStorm对 ...
- ASP.net 中 OutputCache 指令各个参数的作用。
使用@ OutputCache指令 使用@ OutputCache指令,能够实现对页面输出缓存的一般性需要.@ OutputCache指令在ASP.NET页或者页中包含的用户控件的头部声明.这种方式非 ...
- amazeui中css组件、js组件、web组件的区别
amazeui中css组件.js组件.web组件的区别 一.总结 一句话总结: 1.可直接像调用js插件那样调用:在AmazeUI(妹子UI)中,Web组件可以不编写模板而直接使用,若如此,则与JS插 ...
- UIlabel文字大小自适应label宽度变大变小
label.adjustsFontSizeToFitWidth = YES; //默认no
- 容易遗忘的JS知识点整理—hasOwnProperty相关
为了判断一个对象是否包含自定义属性而不是原型链上的属性,我们需要使用继承自 Object.prototype 的 hasOwnProperty方法.hasOwnProperty 是 JavaScrip ...
- matlab 格式化文本文件的解析
比如这样一种格式化的文本文件,文件说明及下载地址:/pub/machine-learning-databases/statlog/german/ 的索引 fid = fopen('german.dat ...