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 ...
随机推荐
- linux下的多线程,pthread_create函数
pthread_create是UNIX环境创建线程函数 头文件 #include<pthread.h> 函数声明 int pthread_create(pthread_t*restrict ...
- js,jquery遍历数组,对象
each的用法 1.数组中的each 复制代码 var arr = [ "one", "two", "three", "four ...
- 【C++竞赛 E】xxx和yyy的旅行
时间限制:1s 内存限制:32MB 问题描述 有n个城市和m条双向铁路.对于任意两个不同的城市x和城市y,两个城市之间有双向铁路,否则有双向公路,通过任意一条直达公(铁)路花费一小时.城市x与城市y存 ...
- [TypeScript] Create random integers in a given range
Learn how to create random integers using JavaScript / TypeScript. /** * Returns a random int betwee ...
- ios开发之手势处理 之手势识别一
#import "ViewController.h" @interface ViewController ()<UIGestureRecognizerDelegate> ...
- [Angular Directive] Create a Template Storage Service in Angular 2
You need to define a <template> to be able to use it elsewhere in your app as a TemplateRef. Y ...
- 手动删除APP里面的账号信息
在Archive项目时,出现了“Your build settings specify a provisioning profile with the UUID “”, however, no suc ...
- iOS QLPreviewController(Quick Look)快速浏览jpg,PDF,world等
#import <QuickLook/QuickLook.h> @interface ViewController ()<QLPreviewControllerDataSource, ...
- TextView中实现跑马灯的最简单方法
几行代码实现跑马灯效果,效果如下: 因为很简单,所以就直接贴代码喽 <TextView android:id="@+id/item1_title_message" andro ...
- WPF 触摸到事件
原文:WPF 触摸到事件 本文从代码底层告诉大家,在触摸屏幕之后是如何拿到触摸点并且转换为事件 在 WPF 界面框架核心就是交互和渲染,触摸是交互的一部分.在 WPF 是需要使用多个线程来做触摸和渲染 ...