QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#765959#8980. Prime GamennkWA 1ms3876kbC++201.7kb2024-11-20 15:46:482024-11-20 15:46:53

Judging History

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

  • [2024-11-20 15:46:53]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3876kb
  • [2024-11-20 15:46:48]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define N 10005
#define MAX 1000004
using namespace std;
vector<int> a;
int cal(int n) {
	return n * (n + 1) / 2;
}
void slove()
{
	int n; cin >> n;
	vector<int> all(n);
	for (auto& x : all)cin >> x;
	int m = a.size();
	vector<vector<int>> cnt(m);
	map<int, vector<int>> addon;
	for (int i = 0; i < m; i++)cnt[i].emplace_back(-1);
	for (int i = 0; i < n; i++) {
		int u = all[i];
		bool is = 1;
		for (int j = 0; j < m;j++) {
			int v = a[j];
			if (u % v == 0) {
				cnt[j].emplace_back(i);
				is = 0;
			}
		}
		if (is and u != 1) {
			if (addon[u].size() == 0) {
				addon[u].emplace_back(-1);
			}
			addon[u].emplace_back(i);
		}
	}
	for (int i = 0; i < m; i++)cnt[i].emplace_back(n);
	for (auto& [u, v] : addon)v.emplace_back(n);
	int ans = (m + addon.size()) * n * (n + 1) / 2;
	
	for (int i = 0; i < m; i++) {
		auto& v = cnt[i];
		int len = v.size();
		for (int j = 1; j < len;j++) {
			int x = v[j] - v[j - 1] - 1 ;
			ans -= cal(x);
		}
	}
	for (auto& [u, v] : addon) {
		int len = v.size();
		for (int j = 1; j < len; j++) {
			int x = v[j] - v[j - 1] - 1;
			ans -= cal(x);
		}
	}
	cout << ans << endl;
}
signed main()
{
	for (int i = 2; i <= 10000; i++) {
		int ok = 0;
		for (int j = 2; j <= sqrt(i); j++) {
			if (i % j == 0) { ok = 1; break; }
		}
		if (!ok) a.push_back(i);
	}
	ios::sync_with_stdio(false), cin.tie(nullptr);
	int t = 1;
//	cin >> t;
	while (t--) {
		slove();
	}
	return 0;
}
/*
3
5
0 5 -2 1 2
9 -4 0 10 5
-4 -1 4 -2 4
10
-6 3 1 0 6 -2 -4 3 0 10
22 65 11 1 -34 -1 -39 -28 25 24
10 9 1 -2 -5 8 -7 -10 -7 -7
1
101
48763
651
*/

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3864kb

input:

10
99 62 10 47 53 9 83 33 15 24

output:

248

result:

ok single line: '248'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3724kb

input:

10
6 7 5 5 4 9 9 1 8 12

output:

134

result:

ok single line: '134'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3876kb

input:

10
99 62 10 47 53 9 83 33 15 24

output:

248

result:

ok single line: '248'

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 3744kb

input:

10
692137 743219 52652 45276 492360 972264 988496 117515 917868 423315

output:

469

result:

wrong answer 1st lines differ - expected: '521', found: '469'