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 <cmath> #define maxn 100010 using namespace std; int sign[maxn];
int pri[maxn];
int tot;
int e;
int n[],k[]; void getpri (){
memset (sign,,sizeof sign);
tot=;
sign[]=sign[]=;
for (int i=;i*i<maxn;i++){
if (!sign[i]){
for (int j=i*i;j<maxn;j+=i){
sign[j]=;
}
}
}
for (int i=;i<maxn;i++){
if (!sign[i]){
pri[tot++]=i;
}
}
} int main (){
long long ans;
getpri ();
int t;
while (cin>>t){
int minnn=maxn+;
for (int i=;i<t;i++){
cin>>n[i]>>k[i];
minnn=min (minnn,n[i]);
k[i]=min (k[i],n[i]-k[i]);
}
ans=;
for (int i=;i<tot&&pri[i]<minnn;i++){ //每次处理单个素因子
e=;
int temp=;
for (int j=;j<t;j++){
temp=;
int flag=n[j];
while (flag){ //求 n! 中因子 pri(i) 的个数
temp+=flag/pri[i];
flag/=pri[i];
}
flag=k[j];
while (flag){
temp-=flag/pri[i];
flag/=pri[i];
}
flag=n[j]-k[j];
while (flag){
temp-=flag/pri[i];
flag/=pri[i];
}
e=min (e,temp);
}//cout<<e<<pri[i];
while (e--){
ans*=pri[i];
}
}
cout<<ans<<endl;
}
return ;
}
fzu 1753 Another Easy Problem的更多相关文章
- UVA-11991 Easy Problem from Rujia Liu?
Problem E Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for ...
- An easy problem
An easy problem Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- UVa 11991:Easy Problem from Rujia Liu?(STL练习,map+vector)
Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...
- POJ 2826 An Easy Problem?!
An Easy Problem?! Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7837 Accepted: 1145 ...
- hdu 5475 An easy problem(暴力 || 线段树区间单点更新)
http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...
- 【暑假】[实用数据结构]UVa11991 Easy Problem from Rujia Liu?
UVa11991 Easy Problem from Rujia Liu? 思路: 构造数组data,使满足data[v][k]为第k个v的下标.因为不是每一个整数都会出现因此用到map,又因为每 ...
- HDU 5475 An easy problem 线段树
An easy problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...
- UVA 11991 Easy Problem from Rujia Liu?(vector map)
Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...
- 数据结构(主席树):HDU 4729 An Easy Problem for Elfness
An Easy Problem for Elfness Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 65535/65535 K (J ...
随机推荐
- http://codepen.io/zhou-yg/pen/NqgPmg 在线编辑器
http://codepen.io/zhou-yg/pen/NqgPmg 在线编辑器
- php error_log 详解
定义和用法 error_log() 函数向服务器错误记录.文件或远程目标发送一个错误. 成功,返回 true,否则返回 false. error_log(error,type,destination, ...
- 关于安卓的log学习
什么时候会产生log文件? 1. 程序异常退出 Uncaused Exception. 2. 程序强制关闭 Force Closed(FC). 3. 程序无响应 Application No Resp ...
- 点击Winform右下角图标,在最前端展示窗口
//调用Windows API 展示窗口到最前端 SwitchToThisWindow(this.Handle, true);//窗体的句柄 this.Handle SwitchToThisW ...
- httrack,webdup,WinHTTrack,WebZip
怎么下载摄像头游戏jabbo,并使其能离线运行?修改 1.摄像头游戏jabbo:JABBO Ultimatum by LiveMurals Interactive电脑为:windows 7 32位.试 ...
- Asp.Net的核心对象
原文地址:http://www.cnblogs.com/fish-li/archive/2011/08/21/2148640.html 1.HttpRuntime 对象在处理Http请求的asp.ne ...
- HDU1242 Rescue(BFS+优先队列)
Rescue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- sqlite数据库方言配置
1. application.properties配置sqlite数据库 spring.datasource.url = jdbc:sqlite:C:/test/sqlite/DB/sqlite.db ...
- More is better(并差集)
More is better Time Limit : 5000/1000ms (Java/Other) Memory Limit : 327680/102400K (Java/Other) To ...
- 高效CSS書寫規範及CSS兼容性
一.選擇器針對性說明 某一元素的多个规则集中,选择器的针对性越高,该规则集的权重也就越高.针对性相同的,后出现的规则集的权重更高. * {} /* a=0 b=0 c=0 d=0 -> spec ...