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;

}

版权声明:本文博客原创文章。博客,未经同意,不得转载。

时间: 2024-08-01 06:10:41

fzu-1753 Another Easy Problem-高速求N!多少个月p的相关文章

fzu 1753 Another Easy Problem

本题题意为求 t (t<150) 个 c (n,m)  (1<=m<=n<=100000)的最大公因子: 本题的难点为优化.主要有两个优化重点.一是每次对单个素因子进行处理,优化每次的数组清零:二是对求阶乘素因子个数的优化 ei=[N/pi^1]+ [N/pi^2]+ …… + [N/pi^n]  其中[]为取整 ei 为数 N!中pi 因子的个数: #include <iostream>#include <cstring>#include <cmat

FZU 1753-Another Easy Problem(求多个组合数的最大公约数)

Another Easy Problem Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice FZU 1753 Appoint description:  xietutu  (2013-03-13)System Crawler  (2015-04-27) Description 小TT最近学习了高斯消元法解方程组,现在他的问题来了,如果是以下的方程,

(DS 《算法入门经典》)UVA 11991 Easy Problem from Rujia Liu?(求第k个v出现的索引)

题目大意: 求第k个v出现的索引 解题思路: 如果能构造出一个数据结构,使得data[v][k]就是第k个v出现的索引值即可求解.data[v]表示数v出现的索引数组, data[v][k]表示第k个v出现的索引. Problem E Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, regional contests like Xi'an 200

fzu 1753 质因数的应用

Another Easy Problem Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description xtt最近学习了高斯消元法解方程组,现在他的问题来了,如果是以下的方程,那么应该如何解呢? C(n1,m1)==0 (mod M) C(n2,m2)==0 (mod M) C(n3,m3)==0 (mod M) ................ C(n

Poj 2826 An Easy Problem?!

地址:http://poj.org/problem?id=2826 题目: An Easy Problem?! Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13016   Accepted: 2003 Description It's raining outside. Farmer Johnson's bull Ben wants some rain to water his flowers. Ben nails tw

POJ2826 An Easy Problem?!(线段交点,三角形面积)

题目链接: http://poj.org/problem?id=2826 题目描述: An Easy Problem?! Description It's raining outside. Farmer Johnson's bull Ben wants some rain to water his flowers. Ben nails two wooden boards on the wall of his barn. Shown in the pictures below, the two b

HDU 2601 An easy problem(暴力枚举/质因子分解)

An easy problem Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7963    Accepted Submission(s): 1920 Problem Description When Teddy was a child , he was always thinking about some simple math p

hdu2601 An easy problem(数学)

题目意思: http://acm.hdu.edu.cn/showproblem.php?pid=2601 给出一个数N,求N=i*j+i+j一共有多少种方案. 题目分析: 此题直接暴力模拟即可,只是需要将上式转化为n+1=(i+1)*(j+1)进行计算即可. AC代码: /** *hdu2601 An easy problem *意思:求n=i*j+i+j的种类 *分析:转化为n+1=(i+1)*(j+1),求解就行了 */ #include<iostream> #include<cst

An Easy Problem?!(细节题,要把所有情况考虑到)

http://poj.org/problem?id=2826 An Easy Problem?! Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10505   Accepted: 1584 Description It's raining outside. Farmer Johnson's bull Ben wants some rain to water his flowers. Ben nails two woode

[POJ] 2453 An Easy Problem [位运算]

An Easy Problem Description As we known, data stored in the computers is in binary form. The problem we discuss now is about the positive integers and its binary form. Given a positive integer I, you task is to find out an integer J, which is the min