QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#766057#8980. Prime GamennkWA 0ms26624kbC++201.5kb2024-11-20 16:03:052024-11-20 16:03:07

Judging History

This is the latest submission verdict.

  • [2024-11-20 16:03:07]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 26624kb
  • [2024-11-20 16:03:05]
  • Submitted

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(1000006);
	vector<int> b;
	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) {
				if (cnt[u].size() == 0) {
					b.push_back(u);
					cnt[u].emplace_back(-1);
				}
				cnt[u].emplace_back(i);
				is = 0;
			}
		}
		if (is and u != 1) {
			if (cnt[u].size() == 0) {
				b.push_back(u);
				cnt[u].emplace_back(-1);
			}
			cnt[u].emplace_back(i);
		}
	}

	int ans = (b.size()) * n * (n + 1) / 2;

	for (int i = 0; i < b.size(); i++) {
		auto& v = cnt[b[i]];
		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 <= 1000; 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
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 26624kb

input:

10
99 62 10 47 53 9 83 33 15 24

output:

385

result:

wrong answer 1st lines differ - expected: '248', found: '385'