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)..... ...
随机推荐
- 关键字: on
关键字: on 数据库在通过连接两张或多张表来返回记录时,都会生成一张中间的临时表,然后再将这张临时表返回给用户. 在使用left jion时,on和where条件的区别如下: 1. on条件是在生成 ...
- java 中设计模式
1. 单例模式(一个类只有一个实例) package ch.test.notes.designmodel; /** * Description: 单例模式 (饿汉模式 线程安全的) * * @auth ...
- tcpdump简单使用
1.使用wincap将文件放入系统任意路径, 2.进入系统,赋文件可执行权限, 3.输入命令:./tcpdump -i eth0 -s 0 -w xxx.pcap 4.进行数据交互 5.退出程序运行, ...
- java常考小程序
private static void nineNineMulitTable(){ /** * 9*9乘法表 */ for (int i = 1,j = 1; j <= 9; i++) { Sy ...
- ios调试技巧
一.概述1.掌握调试技巧,调试技术最基本,最重要的调试手段包括:单步跟踪,断点,变量观察等.单步跟踪(Step)所谓单步跟踪是指一行一行地执行程序,每执行一行语句后就停下来等待指示,这样你就能够仔细了 ...
- 【计数】51nod1677 treecnt
要将答案看做是小问题的贡献和 Description 给定一棵n个节点的树,从1到n标号.选择k个点,你需要选择一些边使得这k个点通过选择的边联通,目标是使得选择的边数最少. 现需要计算对于所有选择k ...
- Educational Codeforces Round 40千名记
人生第二场codeforces.然而遇上了Education场这种东西 Educational Codeforces Round 40 下午先在家里睡了波觉,起来离开场还有10分钟. 但是突然想起来还 ...
- ECshop二次开发 ECSHOP首页显示积分商城里的商品
以ECSHOP2.7.2官方默认模板为基础 1).首先打开 index.php 文件,在最末尾增加下面函数,注意千万不要写到 “?>” 的外面去,要加在“?>”的前面,加以下代码: /** ...
- 基础训练 Sine之舞
Sine之舞 #include<iostream> #include<vector> #include<string.h> using namespace std; ...
- ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph
"Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a ...