Codesforces 485D 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.
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).
Print the answer to the problem.
3
3 4 5
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的更多相关文章
- CodeForces - 485D Maximum Value (数学)
题意: n个数,求出这些数中满足 ai >= aj 的 ai % aj 的最大值. 排序去重,然后对于每一个a[i], 如果找到a[i] 的一个倍数 k*a[i] (k > 1)的位置,那 ...
- Codeforces C. Maximum Value(枚举二分)
题目描述: Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard ...
- POJ3693 Maximum repetition substring [后缀数组 ST表]
Maximum repetition substring Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9458 Acc ...
- Uncaught RangeError: Maximum call stack size exceeded 调试日记
异常处理汇总-前端系列 http://www.cnblogs.com/dunitian/p/4523015.html 开发道路上不是解决问题最重要,而是解决问题的过程,这个过程我们称之为~~~调试 记 ...
- 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.免费应用程序调试最 ...
- MTU(Maximum transmission unit) 最大传输单元
最大传输单元(Maximum transmission unit),以太网MTU为1500. 不同网络MTU如下: 如果最大报文数据大小(MSS)超过MTU,则会引起分片操作. 路径MTU: 网路 ...
- uva 11059 maximum product(水题)——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB1QAAAMcCAIAAABo0QCJAAAgAElEQVR4nOydW7msuhKF2wIasIAHJK
- [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 ...
- [LeetCode] Third Maximum Number 第三大的数
Given a non-empty array of integers, return the third maximum number in this array. If it does not e ...
随机推荐
- 《穷爸爸富爸爸——Cashflow》
读<穷爸爸富爸爸>大约两年前了,当时对理财没什么概念,除了支付宝,就是京东小金库,哪个利率高就存哪个里.记忆中除了感觉这应该是有一定经济基础的人通常做的事,工薪阶级的自己还未达标,工资除了 ...
- win8.1安装Python提示缺失api-ms-win-crt-runtime-l1-1-0.dll问题
Windows下安装python成功之后,运行python,提示缺少api-ms-win-crt-runtime-l1-1-0.dll.很显然,安装上这个dll文件不就可以了吗.于是就开始百度,找资料 ...
- go 复合数据类型
数组 数组是一个由固定长度的特定类型元素组成的序列,一个数组可以由零个或多个元素组成.因为数组的长度是固定的,因此在Go语言中很少直接使用数组. 数组声明方式: #第一种 ] int balance ...
- Python基础篇(格式化输出,运算符,编码):
Python基础篇(格式化输出,运算符,编码): 格式化输出: 格式:print ( " 内容%s" %(变量)) 字符类型: %s 替换字符串 %d 替换整体数字 ...
- dbvisualizer设置自动补全不显示模式名
- firefox下jquery ajax 返回 [object XMLDocument]处理
在firefox下使用jquery ajax处理 返回json类型的时候,ajax执行成功返回结果为 [object XMLDocument]. 处理办法:在getWriter.write():前面加 ...
- 【和孩子一起学编程】 python笔记--第三天
第十章 游戏时间:Skier 首先安装pygame,直接在cmd命令控制框里键入pip install pygame就可以了 代码: import pygame, sys, random skier_ ...
- datagrid+toolbar 不分页 显示
1 新建DataGrid.js文件 /*** * * *el: table id * ***/ function showDataGrid(el) { $(el).datagrid({ title: ...
- php strrev()函数 语法
php strrev()函数 语法 strrev()怎么用? php strrev()函数用于反转字符串,语法是strrev(string),返回已反转的字符串.大理石构件来图加工 作用:反转字符串 ...
- spring boot中读取配置文件的两种方式
application.properties test.name=测试 test.url=www.test.com 1.@Value注解 在controller里可以这样直接调用 @Value(&qu ...