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 ...
随机推荐
- Android学习笔记:Home Screen Widgets(2):关于Widget
通过widget定义,我们在widget列表中看到了我们的TestWidget.当我们拖拽widget到主页时,假设在appwidet-provider中定义了android:configure的ja ...
- 建立简单的服务器端程序 分类: B1_JAVA 2013-10-08 21:53 503人阅读 评论(0) 收藏
参考自core java package com.lujinhong.corejava; import java.io.IOException; import java.io.InputS ...
- 并发队列ConcurrentLinkedQueue 和 阻塞队列LinkedBlockingQueue用法
在Java多线程应用中,队列的使用率很高,多数生产消费模型的首选数据结构就是队列(先进先出).Java提供的线程安全的Queue可以分为阻塞队列和非阻塞队列,其中阻塞队列的典型例子是BlockingQ ...
- auto_create_partition
#!/usr/bin/env python # -*- encoding: utf8 -*- import calendar import time import os import sys from ...
- javascript数组全排列,数组元素所有组合
function permute(input) { var permArr = [], usedChars = []; function main(input){ var i, ch; for (i ...
- Java 学习(22):Java MySQL 连接
Java MySQL 连接 本章节我们为大家介绍 Java 如何使用 使用 JDBC 连接 MySQL 数据库. Java 连接 MySQL 需要驱动包,最新版下载地址为:http://dev.mys ...
- USB 3.0规范中译本 第1章 引言
本文为CoryXie原创译文,转载及有任何问题请联系cory.xie#gmail.com. 1.1 动机(Motivation) Universal Serial Bus (USB) 的原始动机来自于 ...
- hreadPoolExecutor使用和思考(上)-线程池大小设置与BlockingQueue的三种实现区别
阅读更多 工作中多处接触到了ThreadPoolExecutor.趁着现在还算空,学习总结一下. 前记: jdk官方文档(javadoc)是学习的最好,最权威的参考. 文章分上中下.上篇中主要介绍Th ...
- js进阶 11-1 jquery中的页面内容操作的三个方法
jquery中的页面内容操作的三个方法 一.总结 一句话总结:记三个方法即可.text,html,val.因为这里是方法,所以设置值的是后面方法的参数. 1.jquery中的页面内容操作的三个方法? ...
- js实现去文本换行符小工具
js实现去文本换行符小工具 一.总结 一句话总结: 1.vertical属性使用的时候注意看清定义,也注意父元素的基准线问题.vertical-align:top; 2.获取textareaEleme ...