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 ...
随机推荐
- 【心情】"支NMLGB配树”
大视野oj坏了 那就做杭电呗 看看大触都做杭电里的哪些题 看到杭电的分类了 Tarjan算法诶,我好像会嘛,就是你了 诶,怎么不是求强连通分量? 哦,原来是Tarjan算法的另外一个应用叫做支配树 我 ...
- 【30.93%】【codeforces 558E】A Simple Task
time limit per test5 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...
- Loader之一:基本原理 分类: H1_ANDROID 2013-11-16 10:29 1923人阅读 评论(0) 收藏
参考APIDEMO及http://developer.android.com/guide/components/loaders.html#app 1.Introduced in Android 3.0 ...
- ServerSocketChannel API用法
java.nio.channels 类 ServerSocketChannel java.lang.Object java.nio.channels.spi.AbstractInterruptible ...
- [SCSS] Use Standard Built-in SCSS Functions for Common Operations
We can use javascript for color and opacity variations, math, list and map logic or to see if someth ...
- 资源载入和页面事件 load, ready, DOMContentLoaded等
资源载入和页面事件 理想的页面载入方式 解析HTML结构. 载入并解析外部脚本. DOM树构建完成,运行脚本.//DOMInteractive –> DOMContentLoaded 载入图片. ...
- PHP数组foreach循环如何实现逆序访问?
PHP数组foreach循环如何实现逆序访问? 一.总结 1.array_reverse($array) :foreach(array_reverse($array) as $key=>$val ...
- MySQL慢日志的相关参数
slow-query-log = on #开启MySQL慢查询功能 slow_query_log_file = /data/mysql/testdb-slow.log #设置MySQL慢查询日志路径 ...
- mysql官网下载linux版本安装包
原文地址:点击打开链接 今天在Linux上部署项目,用到了Mysql,因此想要下载适用于Linux的安装版本,在Mysql官网找了半天,终于找到怎样下载了,这里写出来,以后大家找的时候就好找了. 第一 ...
- 使用apidoc 生成Restful web Api文档
在项目开发过程中,总会牵扯到接口文档的设计与编写,之前使用的都是office工具,写一个文档,总也是不够漂亮和直观.好在git上的开源大神提供了生成文档的工具,so来介绍一下! 该工具是Nodejs的 ...