Maximum Value(Codeforces_484B)
来源:互联网 发布:java android pdf 编辑:程序博客网 时间:2024/05/29 09:48
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.
Sample test(s)
Input
3
3 4 5
Output
2
#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>using namespace std;int main(){ int n; int a,num[2000100]; scanf("%d",&n); int maxx=-99999; for(int i=1;i<=n;i++) { scanf("%d",&a); num[a]=a; maxx=max(maxx,a); } for(int i=1;i<=maxx*2+1;i++) { if(num[i]!=i) num[i]=num[i-1];//这样处理一下更高效 } int ans=0; for(int i=2;i<maxx;i++) { if(num[i]==i) { for(int j=i*2;j<=maxx*2+1;j+=i)//枚举i的倍数 { if(num[j-1]>i)//与i取余所能得到的最大值只会在比i的倍数小的数中的最大值中出现 ans=max(ans,num[j-1]%i);//(有点绕,譬如有四个数3,4,5,6,i=3,比i的2倍小的数有4,5,最大的是5,所以5%3是当前所得到的最大余数 } } } printf("%d\n",ans); return 0;}
0 0
- Maximum Value(Codeforces_484B)
- Maximum Value
- Maximum Value
- CF_484B Maximum Value(二分)
- Maximum Value(哈希)
- codeforces D. Maximum Value
- maximum average value
- Maximum Value CodeForces
- Maximum Value Problem FZU
- CodeForces 484B Maximum Value
- FZU 2037 Maximum Value Problem
- 4.1 Maximum and Minimum Value
- Maximum value's random index
- Codeforces 484B Maximum Value
- codeforces 485D. Maximum Value
- Find Nth maximum value in SQL Server
- FZU2037 Maximum Value Problem 规律 + 递推
- Maximum Value - CodeForces 484 B 水题
- pat-旧键盘
- project.pbxproj 文件的学习
- 【C++/数据结构】顺序表的基本操作
- linux下tmpfs文件系统简介
- 安装JavaJDK,三步搞定。
- Maximum Value(Codeforces_484B)
- C#datatable实例
- python中的文件编码方式
- 各种排序算法的总结和实现。
- 常见文件系统的格式
- Java注解Annotation详解
- Ubuntu 14.04 安装virtualbox 虚拟机之后无法读取usb 设备问题
- android studio 安装出现两个图标
- tomcat执行一个java类