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)..... ...
随机推荐
- UVa 12219 Common Subexpression Elimination (stl,模拟,实现)
一般来说,把一颗子树离散成一个int,把一个结点的字符离散成一个int会方便处理 直接map离散.当然一个结点最多只有4个小写字母,也可以直接编码成一个27进制的整数,舍掉0,为了区分0和0000. ...
- Robot Framework(十) 执行测试用例——测试执行
3.2测试执行 本节描述如何执行从解析的测试数据创建的测试套件结构,如何在失败后继续执行测试用例,以及如何正常停止整个测试执行. 3.2.1执行流程 执行套房和测试 设置和拆卸 执行顺序 3.2.2继 ...
- Java——舞动的排序
一.冒泡排序: http://v.youku.com/v_show/id_XMzMyOTAyMzQ0.html //冒泡排序 public class Bubbling { public static ...
- MYSQL 注射精华
前言鄙人今天心血来潮突然想写篇文章,鄙人从来没写过文章,如果有错误的地方请多多指教.本文需要有基础的SQL语句知识才可以更好的理解.建议想学习的人多去了解一下SQL语句和编程语言,知己知彼才能百战百胜 ...
- javascript的trigger事件
<html> <head> <script type="text/javascript" src="/jquery/jquery.js&qu ...
- ios之UIProgressView
UIProgressView和UIActivityIndicator有些类似 但是不同之处在于, UIProgressView能够更加精确的反应进度 UIActivityIndicator则只能表 ...
- PAT 乙级 1005
题目 题目地址:PAT 乙级 1005 题解 本题主要就在于将一个数的一系列计算结果不重复地存储起来并便于检索,考虑到STL中的集合有相似的特性,使用set可以有效地简化代码和运算. 过程如下: (初 ...
- 【贪心 思维题】[USACO13MAR]扑克牌型Poker Hands
看似区间数据结构的一道题 题目描述 Bessie and her friends are playing a unique version of poker involving a deck with ...
- 【OS_Linux】Linux系统中目录及文件管理
1.Linux系统中目录的树状结构 目录 /bin 存放二进制可执行文件(ls,cat,mkdir等),常用命令一般都在这里. /etc 存放系统管理和配置文件 /home 存放所有用户文件的根目录, ...
- GIMP做成颜色蒙板
效果图: 原始的美女图片上盖了一层的颜色,这个是想出来的效果,只是用来实践学到的技能,具体的场景还没有确定. 1/首先打开原始的美女图片: 2/然后在添加一张新的图片,作为新的图层添加进来: 这样的话 ...