QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#153497#1336. Non-Trivial Common DivisorrmqTL 0ms0kbC++141.0kb2023-08-30 08:31:042023-08-30 08:31:05

Judging History

你现在查看的是最新测评结果

  • [2023-08-30 08:31:05]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-08-30 08:31:04]
  • 提交

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

output:


result: