它计算每个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的更多相关文章

  1. fzu 1753 Another Easy Problem

    本题题意为求 t (t<150) 个 c (n,m)  (1<=m<=n<=100000)的最大公因子: 本题的难点为优化.主要有两个优化重点.一是每次对单个素因子进行处理,优 ...

  2. POJ 2826 An Easy Problem?!

    An Easy Problem?! Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7837   Accepted: 1145 ...

  3. HDU 5475 An easy problem 线段树

    An easy problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...

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

    An Easy Problem   Description As we known, data stored in the computers is in binary form. The probl ...

  5. Another Easy Problem fzu1753

    Another Easy Problem Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u ...

  6. zzuli 1815: easy problem 打表

    1815: easy problem Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 243  Solved: 108 SubmitStatusWeb ...

  7. hdu2601 An easy problem(数学)

    题目意思: http://acm.hdu.edu.cn/showproblem.php? pid=2601 给出一个数N,求N=i*j+i+j一共同拥有多少种方案. 题目分析: 此题直接暴力模拟就可以 ...

  8. UESTC 1591 An easy problem A【线段树点更新裸题】

    An easy problem A Time Limit: 2000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others ...

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

    http://poj.org/problem?id=2826 An Easy Problem?! Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

  10. POJ 2826 An Easy Problem?![线段]

    An Easy Problem?! Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12970   Accepted: 199 ...

随机推荐

  1. 【24.17%】【codeforces 721D】Maxim and Array

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. adb常用命令 分类: H1_ANDROID 2013-09-08 15:22 510人阅读 评论(0) 收藏

    安装软件  adb install apk文件名称.apk  重新安装该软件  adb install -r apk文件名称.apk  卸载apk软件  adb uninstall apk包名.apk ...

  3. 【Bash百宝箱】Linux shell学习

    shell特点-- Linux有多种shell能够使用,默认的为bash,bash有以下几个主要特点. 1.命令记忆能力 在命令行中按上下键能够找到一个前/后输入的命令.这些命令记录在-/.bash_ ...

  4. css3-1 css3游戏介绍、css3样式和优先级

    css3-1 css3游戏介绍.css3样式和优先级 一.总结 一句话总结:我们写外部css表的时候可以用class,那样使用的人用id修改的话优先级就比我们高,达到目的. 1.html嵌套css样式 ...

  5. css 水平垂直居中的方法总结

    在项目中经常会遇到设置元素水平垂直居中的需求.而且具体的场景也不同,所以将个人总结的方法做个汇总,希望对浏览者有用. 以下所举的例子都以一个html为准,这里规定好一些公用样式. body { bac ...

  6. RandomStringUtils RandomUtils

    上一篇是StringUtils 链接http://www.cnblogs.com/tele-share/p/8060129.html 1.RandomStringUtils 1.1模拟实现random ...

  7. [Redux] Avoid action type naming conflicts

    In redux, the action type is just a normal string type, it is easy to get naming conflicts in large ...

  8. 正則表達式基础及java使用

    正則表達式基础 正則表達式语法(1)     普通字符:字母,数字.汉子,下划线以及没有特殊定义的标点符号都是"普通字符".表达式中的普通字符.在匹配一个字符串的时候,匹配与之同样 ...

  9. html5和html的区别是什么(精问)

    html5和html的区别是什么(精问) 一.总结 一句话总结:html5:简洁(文档生命,链接引入) 语义化(语义化标签)  API(canvas,地理位置等)  一些标签(input新类型) 二. ...

  10. java十五个常用类学习及方法举例

    <code class="language-java">import java.util.Scanner; import java.util.Properties; i ...