QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#765969#8980. Prime GamennkWA 13ms4104kbC++201.7kb2024-11-20 15:49:442024-11-20 15:49:45

Judging History

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

  • [2024-11-20 15:49:45]
  • 评测
  • 测评结果:WA
  • 用时:13ms
  • 内存:4104kb
  • [2024-11-20 15:49:44]
  • 提交

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 tmp=addon.size();
	int ans = (m + tmp) * 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 <= 100000; 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: 10ms
memory: 4028kb

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: 6ms
memory: 4104kb

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: 10ms
memory: 3932kb

input:

10
99 62 10 47 53 9 83 33 15 24

output:

248

result:

ok single line: '248'

Test #4:

score: 0
Accepted
time: 10ms
memory: 4036kb

input:

10
692137 743219 52652 45276 492360 972264 988496 117515 917868 423315

output:

521

result:

ok single line: '521'

Test #5:

score: -100
Wrong Answer
time: 13ms
memory: 4036kb

input:

100
408775 951905 198113 227169 170826 717434 172837 379198 720110 733849 256909 997639 834222 642949 317137 409227 410206 641528 625980 937295 557730 566754 910637 716940 949428 513251 236121 195566 241377 442709 617863 89943 809036 620607 976274 444954 341290 780899 673131 169536 855557 140849 834...

output:

249396

result:

wrong answer 1st lines differ - expected: '255236', found: '249396'