QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#153497 | #1336. Non-Trivial Common Divisor | rmq | TL | 0ms | 0kb | C++14 | 1.0kb | 2023-08-30 08:31:04 | 2023-08-30 08:31:05 |
answer
#include"bits/stdc++.h"
#define int long long
using namespace std;
int read() {
int x = 0, fff = 1;
char c;
while ((c = getchar()) < '0' || c > '9')
if (c == '-')
fff = -1;
while (c >= '0' && c <= '9')
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return x * fff;
}
const double eps = 1e-6;
const int N = 2e3 + 5;
const int M = 100 + 5;
const int V = 10;
const int mod = 998244353;
const int bse = 998244353;
const int inf = 1e9;
const double pi = acos(-1);
int n;
int a[N];
unordered_map<int, int>hsh;
int ans;
signed main() {
freopen("1.in", "r", stdin);
n = read();
for(int i = 1; i <= n; i++) {
int x;
x = read();
int tmp = x;
for(int i = 2; i <= sqrt(x); i++) {
if(i * i == x) {
hsh[i] += tmp;
ans = max(ans, hsh[i]);
break;
}
if(x % i == 0) {
// while(x % i == 0) x /= i;
hsh[i] += tmp;
ans = max(ans, hsh[i]);
}
}
hsh[x] += tmp;
ans = max(ans, hsh[x]);
}
printf("%lld\n", ans);
return 0;
}
/*
5 2
5 5 5 5 5
2 2
*/
详细
Test #1:
score: 0
Time Limit Exceeded
input:
6 1 2 3 4 5 6