比赛 !信心赛 评测结果 AAAAAAAAATAAATTTTTATTTTTTTTTTTTTTTTTTT
题目名称 《数列》 最终得分 27
用户昵称 LikableP 运行时间 104.508 s
代码语言 C++ 内存使用 1.78 MiB
提交时间 2026-01-17 11:24:15
显示代码纯文本
#include <cstdio>
#include <algorithm>

const int MAXN = 1e5 + 10;

int n;
int a[MAXN], pos[MAXN];
int ans;

int main() {
  #ifdef LOCAL
    freopen("!input.in", "r", stdin);
    freopen("!output.out", "w", stdout);
  #else
    freopen("arrayy.in", "r", stdin);
    freopen("arrayy.out", "w", stdout);
  #endif

  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    pos[i] = i;
  }

  do {
    int x = a[pos[1]];
    for (int i = 2; i <= n; ++i) {
      x = x % a[pos[i]];
    }
    ans = std::max(ans, x);
  } while (std::next_permutation(pos + 1, pos + n + 1));

  printf("%d\n", ans);
  return 0;
}