NOJ1203 最多约数问题 [搜索 数论]
|
Accepted
|
79MS
|
1400K
|
2321Byte
|
2015-01-25 13:14:25.0
|
最多约数问题
总提交 : 431 测试通过 : 52
题目描述
输入
输入的第1行有两个正整数a和b。
输出
若找到的a和b之间约数个数最多的数是x,则输出div(x)。
样例输入
1 36
样例输出
9
题目来源
算法设计与实验题解
先转一发大仙的题解:
http://blog.csdn.net/u012968092/article/details/41975317
我的优化:稍微改了下搜索顺序,因为新增加一种素因子在大部分情况下,比新增加当前已有的一个素因子来的收益大~
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<string> #define N 100005
#define M 105
#define mod 1000000007
//#define p 10000007
#define mod2 1000000000
#define ll long long
#define LL long long
#define eps 1e-6
#define inf 1000000
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b) using namespace std; ll a,b;
ll ma;
int f[N];
ll p[N];
ll ccnt; void ini1()
{
memset(f,,sizeof(f));
ll i,j;
ccnt=;
f[]=f[]=;
for(i=;i<=N-;i++){
if(f[i]==) continue;
for(j=*i;j<=N-;j+=i){
f[j]=;
}
}
for(i=;i<=N-;i++){
if(f[i]==){
p[ccnt]=i;ccnt++;
}
}
// printf(" cnt=%d\n",cnt);
} ll quickpow(ll x,ll n)
{
ll re=;
while(n)
{
if( (n&)!= ){
re*=x;
}
n/=;
x*=x;
}
return re;
} void dfs(ll st,ll now,ll cnt)
{
ll i;
//printf(" st=%I64d p=%I64d now=%I64d cnt=%I64d ma=%I64d\n",st,p[st],now,cnt,ma);
if(now>b) return;
if(now>=a){
ma=max(ma,cnt);
}
ll temp=log(b/now)/log(p[st]);
ll re=quickpow(,temp);
// printf(" temp=%I64d re=%I64d ma=%I64d\n",temp,re,ma);
if(re*cnt<=ma) return;
if( now<a && (a-)/now==b/now ) return;
ll c=;
ll te=now;
// printf(" te=%I64d now=%I64d\n",te,now);
if(st>=ccnt) return;
for(i=;;i++){
if(te>b) break;
// printf(" nst=%I64d te=%I64d ncnt=%I64d\n",st+1,te,(c+1)*cnt);
dfs(st+,te,(c+)*cnt);
te*=p[st];
c++;
}
} void ini()
{
ma=;
} void solve()
{
if(a>b) swap(a,b);
if(b==){
ma=;return;
}
ma=;
dfs(,,);
} void out()
{
//printf("%I64d\n",ma);
cout<<ma<<endl;
} int main()
{
ini1();
//freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
//scanf("%d",&T);
//for(int ccnt=1;ccnt<=T;ccnt++)
//while(T--)
// while(scanf("%I64d%I64d",&a,&b)!=EOF)
while(cin>>a>>b)
{
ini();
solve();
out();
}
return ;
}
|
Time Limit Exceed at Test 5
|
2323Byte
|
2015-01-25 13:17:03.0
|
|||||
|
|
|||||||
|
Wrong Answer at Test 5
|
2167Byte
|
2015-01-25 12:58:23.0
|
|||||
|
Wrong Answer at Test 5
|
2120Byte
|
2015-01-25 12:52:13.0
|
|||||
|
Wrong Answer at Test 5
|
2120Byte
|
2015-01-25 12:49:17.0
|
|||||
|
Wrong Answer at Test 5
|
2136Byte
|
2015-01-25 12:44:20.0
|
|||||
|
Wrong Answer at Test 5
|
2137Byte
|
2015-01-25 12:43:30.0
|
|||||
|
Wrong Answer at Test 5
|
2140Byte
|
2015-01-25 12:42:43.0
|
|||||
|
Wrong Answer at Test 5
|
2140Byte
|
2015-01-25 12:39:31.0
|
|||||
|
Runtime Error at Test 7
(STACK_OVERFLOW) |
2115Byte
|
2015-01-25 12:38:30.0
|
|||||
|
Accepted
|
947MS
|
712K
|
2818Byte
|
2015-01-23 22:26:01.0
|
|||
|
Time Limit Exceed at Test 3
|
2825Byte
|
2015-01-23 22:25:01.0
|
|||||
|
Accepted
|
970MS
|
712K
|
2812Byte
|
2015-01-23 21:20:34.0
|
|||
|
2844Byte
|
2015-01-23 21:19:14.0
|
||||||
|
Time Limit Exceed at Test 3
|
2173Byte
|
2015-01-23 21:17:06.0
|
|||||
|
Wrong Answer at Test 3
|
1830Byte
|
2015-01-23 21:02:14.0
|
|||||
|
Wrong Answer at Test 3
|
1806Byte
|
2015-01-23 20:58:55.0
|
|||||
|
Wrong Answer at Test 3
|
1804Byte
|
2015-01-23 20:57:37.0
|
|||||
|
Runtime Error at Test 3
(ACCESS_VIOLATION) |
1795Byte
|
2015-01-23 20:57:00.0
|
NOJ1203 最多约数问题 [搜索 数论]的更多相关文章
- 【BZOJ1968】约数研究(数论)
[BZOJ1968]约数研究(数论) 题面 BZOJ链接(题目是图片形式的) 题解 傻逼题 \(NOIP\) \(T1\)难度 不会做的话您可以退役 #include<iostream> ...
- 【51Nod1584】加权约数和(数论)
[51Nod1584]加权约数和(数论) 题面 51Nod 题解 要求的是\[\sum_{i=1}^n\sum_{j=1}^n max(i,j)\sigma(ij)\] 这个\(max\)太讨厌了,直 ...
- 牛客:t次询问,每次给你一个数n,求在[1,n]内约数个数最多的数的约数个数(数论+贪心)
https://ac.nowcoder.com/acm/contest/907/B t次询问,每次给你一个数n,求在[1,n]内约数个数最多的数的约数个数 分析: 根据约数和定理:对于一个大于1正整数 ...
- 洛谷P1221 最多因子数 [搜索,数学]
题目传送门 最多因子数 目描述 数学家们喜欢各种类型的有奇怪特性的数.例如,他们认为945是一个有趣的数,因为它是第一个所有约数之和大于本身的奇数. 为了帮助他们寻找有趣的数,你将写一个程序扫描一定范 ...
- LOJ #2234. 「JLOI2014」聪明的燕姿(搜索 + 数论)
题意 给出一个数 \(S\) ,输出所有约数和等于 \(S\) 的数. \(S \le 2 \times 10^9\) ,数据组数 \(\le 100\) . 题解 首先用约数和定理: \[ \beg ...
- 【BZOJ1053】[HAOI2007]反素数 (搜索+数论)
\([POI2002][HAOI2007]\)反素数 题目描述 对于任何正整数x,其约数的个数记作\(g(x)\).例如\(g(1)=1.g(6)=4\). 如果某个正整数x满足:\(g(x)> ...
- UVA - 294 Divisors (约数)(数论)
题意:输入两个整数L,U(1<=L<=U<=109,U-L<=10000),统计区间[L,U]的整数中哪一个的正约数最多.如果有多个,输出最小值. 分析: 1.求一个数的约数, ...
- 最多约数问题(Java)
Description 正整数x 的约数是能整除x 的正整数.正整数x的约数个数记为div(x).例如,1,2,5,10 都是正整数10的约数,且div(10)=4.设a 和b是2 个正整数,a≤b, ...
- zoj2562:搜索+数论(反素数)
题目大意:求n以内因子数量最多的数 n的范围为1e16 其实相当于求n以内最大的反素数... 由素数中的 算数基本原理 设d(a)为a的正因子的个数,则 d(n)=(a1+1)(a2+1)..... ...
随机推荐
- windows中安装模拟器后修改模拟器中的hosts方法
1.背景 有的时候我们测试安卓的app需要绑定hosts,这个时候我们如果只是修改PC机器上的hosts,然而在模拟器中并不生效.这个时候我们就需要修改模拟器中的hosts. 模拟器中的hosts为只 ...
- Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.Reason: Failed to determine a suitable driver class
解决方案: @SpringBootApplication(exclude = DataSourceAutoConfiguration.class) 作用://取消数据库配置 但是 在用到数据库的时候记 ...
- ArcGis server连接oracle
ArcGIG server连接Oracle 目录--gis服务器--添加arcgis server 下一步: 身份验证为在arcgis server manager 中的管理员登录密码和账户 对于服务 ...
- PHP的PDF扩展库TCPDF将中文字体设置为内嵌字体的方法
1. 下载要设置的字体,如名为simfang.ttf,放在./vendor/tecnickcom/tcpdf/tools目录中 2.在tools目录中按住shift,点击鼠标右键,点击“在此处打开命令 ...
- Django2.x中url路由的path()与re_path()参数解释
在新版本Django2.x中,url的路由表示用path和re_path代替,模块的导入由django1.x版本的from django.conf.urls import url,include变成现 ...
- 【Git版本控制】git---从已有分支拉出新的分支
参考博文:git---从已有分支拉出新分支
- SQL server的GO用法--巨坑
SQL脚本是一种用SQL语言写的批处理文件(.sql),SQL脚本通常可以由SQL查询分析器来执行. ================================================= ...
- 数据结构( Pyhon 语言描述 ) — — 第8章:队列
队列概览 队列是线性的集合 队列的插入限制在队尾,删除限制在队头.支持先进先出协议( FIFIO, first-in first-out ) 两个基本操作 add:在队尾添加一项 pop:从队头弹出一 ...
- 【ORACLE】调整序列的当前种子值
[ORACLE]调整序列的当前种子值 --必须用SYS用户执行脚本:或具有SYSDBA角色登录: CREATE OR replace ); v_step ):;--步进 tsql ); BEGIN E ...
- MFC中Picture控件显示图像
图片显示在picture控件中,整个软件最小化后图片消失问题. 解决方案:OpenCV学习笔记(9)利用MFC的Picture控件显示图像+播放视频和捕获摄像头画面 - CSDN博客 http:// ...