CodeForces 484B 数学 Maximum Value

很有趣的一道题,题解戳这

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 using namespace std;
 6 
 7 const int maxn = 200000 + 10;
 8 const int maxm = 1000000 + 10;
 9 
10 int a[maxn], f[maxm];
11 
12 int main()
13 {
14     int n; scanf("%d", &n);
15     for(int i = 0; i < n; i++) scanf("%d", a + i);
16     sort(a, a + n);
17     n = unique(a, a + n) - a;
18 
19     int M = a[n-1];
20     for(int i = 0; i < n; i++)
21         for(int j = a[i] + 1; j <= a[i+1]; j++) f[j] = a[i];
22 
23     int ans = 0;
24     for(int i = 0; i < n; i++)
25     {
26         for(int j = a[i] * 2; j <= M; j += a[i])
27         {
28             ans = max(ans, f[j] % a[i]);
29         }
30         ans = max(ans, M % a[i]);
31     }
32     printf("%d\n", ans);
33 
34     return 0;
35 }
代码君

 

posted @ 2015-08-02 08:54  AOQNRMGYXLMV  阅读(174)  评论(0编辑  收藏  举报