博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Maximum Value(CodeForces - 484B)
阅读量:7063 次
发布时间:2019-06-28

本文共 1068 字,大约阅读时间需要 3 分钟。

Maximum Value

Time limit 1000 ms

Memory limit 262144 kB

You are given a sequence a consisting of n integers. Find the maximum possible value of  (integer remainder of ai divided by aj), where 1 ≤ i, j ≤ n and ai ≥ aj.

Input

The first line contains integer n — the length of the sequence (1 ≤ n ≤ 2·105).

The second line contains n space-separated integers ai (1 ≤ ai ≤ 106).

Output

Print the answer to the problem.

Example

Input
3 3 4 5
Output
2 题意:求aj%ai的最大值,其中j>i; 分析:每次寻找小于k*aj的最大值,类似于素数筛,例如n=5时,3 4 5 6 7 ,我们如果查找对3取模的最大值,毫无疑问就是找到3到2*3中间的最大值; AC代码:
#include
#include
#include
#include
#include
#include
#define N 2*100000+10const int maxn=1000000+10;typedef long long ll;using namespace std;int a[N];int n;int C(int x){ int w=x,ans=0; while (w
=0;i--){ if (i
=a[i]-1) break; ans=max(ans,C(a[i])); } printf("%d\n",ans); return 0;}

 

 

转载于:https://www.cnblogs.com/lisijie/p/8424744.html

你可能感兴趣的文章
关于I/O上下拉电阻的应用总结
查看>>
JAVA NIO 选择器
查看>>
使用Setup安装Windows8 RTM方法
查看>>
虚度的日子们
查看>>
类似股软(大智慧)之键盘精灵的 vc2008--UNICODE 环境实现
查看>>
POJ 3694 LCA
查看>>
Windows服务程序和安装程序制作
查看>>
转载: Vim 练级攻略
查看>>
嵌入式开发常用的一些命令
查看>>
oracle监听动态注册与静态注册
查看>>
C语言-删除注释
查看>>
java 动态代理
查看>>
微信5.0绑定银行卡教程
查看>>
mac下搭建java开发环境:eclipse+tomcat+maven
查看>>
数字转换为壹仟贰佰叁拾肆的Java方法
查看>>
尝试使用word发布博客
查看>>
hadoop2.2.0 + hbase 0.94 + hive 0.12 配置记录
查看>>
漫游Ruby
查看>>
PHP——自定义比较算法
查看>>
KbmMW 4.40.00 正式版发布
查看>>