D. Maximum Value
 

You are given a sequence a consisting of n integers. Find the maximum possible value of  (integer remainder of ai divided byaj), 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.

Sample test(s)
input
3
3 4 5
output
2

给出 n 个数 a[0] ~ a[n-1] ,要你找出 a[i] % a[j] 最大.

处理一个数组x[i]表示 1~i 离i最近的数是什么。就可以过了。

#include <bits/stdc++.h>
using namespace std; typedef long long LL;
const int mod = (1e9+);
const int N = ;
bool num[N];
int x[N] , a;
int main()
{
int n ;
cin >> n ;
for( int i = ; i < n ; ++i ) {
cin >> a;
num[a] = ;
}
for( int i = ; i <= 2e6 ; ++i ){
if( num[i] )x[i] = i ;
else x[i] = x[i-] ;
}
int res = ;
for( int i = ; i <= 1e6 ; ++i ) if( num[i] ){
for( int j = * i ; j <= 2e6 ; j += i ) {
res = max( res , ( x[j-] ) % i );
}
}
cout << res << endl;
}

Codesforces 485D Maximum Value的更多相关文章

  1. CodeForces - 485D Maximum Value (数学)

    题意: n个数,求出这些数中满足 ai >= aj 的 ai % aj 的最大值. 排序去重,然后对于每一个a[i], 如果找到a[i] 的一个倍数 k*a[i] (k > 1)的位置,那 ...

  2. Codeforces C. Maximum Value(枚举二分)

    题目描述: Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. POJ3693 Maximum repetition substring [后缀数组 ST表]

    Maximum repetition substring Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9458   Acc ...

  4. Uncaught RangeError: Maximum call stack size exceeded 调试日记

    异常处理汇总-前端系列 http://www.cnblogs.com/dunitian/p/4523015.html 开发道路上不是解决问题最重要,而是解决问题的过程,这个过程我们称之为~~~调试 记 ...

  5. iOS---The maximum number of apps for free development profiles has been reached.

    真机调试免费App ID出现的问题The maximum number of apps for free development profiles has been reached.免费应用程序调试最 ...

  6. MTU(Maximum transmission unit) 最大传输单元

    最大传输单元(Maximum transmission unit),以太网MTU为1500. 不同网络MTU如下: 如果最大报文数据大小(MSS)超过MTU,则会引起分片操作.   路径MTU: 网路 ...

  7. uva 11059 maximum product(水题)——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB1QAAAMcCAIAAABo0QCJAAAgAElEQVR4nOydW7msuhKF2wIasIAHJK

  8. [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字

    Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...

  9. [LeetCode] Third Maximum Number 第三大的数

    Given a non-empty array of integers, return the third maximum number in this array. If it does not e ...

随机推荐

  1. java反射(一)--认识反射机制

    一.认识java反射机制 在java语言中,之所以会有如此众多的开源技术支撑,很大的一部分来源于java最大特征--反射机制.能够灵活的去使用反射机制进行项目的开发与设计,才能够真正接触到java的精 ...

  2. 三、python之文件的处理

    1.文件的读取 1.1 读取整个文件 假设我们有一个叫做“hello.txt”的文件,文件内容如下: helloWorld helloPython helloJava 在该文件中,有三行字符串,接下来 ...

  3. 基于Windows 7(本地)和CentOS7.6(云端)的Minecraft服务器(无Forge/有Forge)搭建方法

    炎炎夏日中想和小伙伴们开黑的同学可以进来看一下了,本教程教你搭建基于两个平台的Minecraft服务器,这里我以Minecraft 1.11.2版本为例给大家讲解搭建流程.其中有Forge版本可以加入 ...

  4. Linux下的上传和下载yum install -y lrzsz

    先使用命令 yum install -y lrzsz rz 上传    或者直接拖动 sz 要下的文件 回车

  5. web之请求转发与重定向

    请求转发: 重定向:

  6. ECUST_Algorithm_2019_3

    简要题意及解析 1001 给出一个\(n\times m\)连连看的局面,下面有\(q\)次询问:两个位置的块能否消去,即两个位置的连线是否能少于两次转折,回答\(YES/NO\).与一般的连连看不同 ...

  7. Qt 显示网页的控件

    Qt5.6以下的版本,基于QtWebkit控件Qt5.6以上的MSVC版本,基于 Chromium 的浏览器引擎 Qt WebEngineQt5.6以上的mingw 版本,只能采用QAxWidget ...

  8. boost库:多线程

    1.线程管理 最重要的一个类是boost::thread,是在boost/thread.hpp里定义的,用来创建一个新线程. #include <boost/thread.hpp> #in ...

  9. delphi 读写记录类型文件Record

    type personInfo=Record //定义Record Name:String[10]; Age:integer; end; //写记录包括新键与添加记录 procedure WriteR ...

  10. 树状数组,Fenwick Tree

    Fenwick Tree, (also known as Binary Indexed Tree,二叉索引树), is a high-performance data structure to cal ...