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)..... ...
随机推荐
- WPF知识点全攻略05- XAML内容控件
此处简单列举出布局控件外,其他常用的控件: Window:WPF窗口 UserControl:用户控件 Page:页 Frame:用来浏览Page页 Border:嵌套控件,提供边框和背景. Butt ...
- linux_1
注: 创建软连接: "ln -s xxx 路径1" 在路径1创建xxx的软连接 特点: 1.文件类型 l 2.相当于windows的快捷方式 创建硬链接: "ln xxx ...
- Codeforces Round #273 (Div. 2)-B. Random Teams
http://codeforces.com/contest/478/problem/B B. Random Teams time limit per test 1 second memory limi ...
- 公共Service的抽取小例
package cn.sxx.service; import java.util.List; public interface BaseService<T,Q> { public void ...
- JavaScript -- 语法和数据类型
前戏 前面学了HTML和CSS相关的知识,那JavaScript是做什么的呢?你在网页上看到的那些炫酷的特效都是通过JS来实现的,所以,想要开发一个逼格满满的web页面,JS是必须要会的 什么是Jav ...
- Bootstrap历练实例:验证状态
验证状态 Bootstrap 包含了错误.警告和成功消息的验证样式.只需要对父元素简单地添加适当的 class(.has-warning. .has-error 或 .has-success)即可使用 ...
- 请大神看看10.10Beta1的AppleRTC怎么破?原版会导致BIOS重置!
看起来 跟10.9一样 sudo perl -pi -e 's|\x75\x2e\x0f\xb6|\xeb\x2e\x0f\xb6|' /System/Library/Extensions/Apple ...
- HUAWEI交换机配置telnet登录
Huawei交换机配置Telnet登录 一,交换机开启Telnet服务 <Huawei>system-view ...
- 解析Java finally
以下用几个简单的例子介绍一下finally的用法: 例子1 public class Test { public static void main(String[] args) { System.ou ...
- CSS3-文本-word-wrap,word-break,white-space
一.word-wrap使用: 语法: word-wrap : normal | break-word 取值说明: 1.normal为默认值,当其值为normal控制连续文本换行(允许内容顶开容器的边界 ...