QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#765940 | #8980. Prime Game | nnk | WA | 1ms | 3856kb | C++20 | 1.7kb | 2024-11-20 15:43:33 | 2024-11-20 15:43:41 |
Judging History
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 <= 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
*/
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3568kb
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: 0ms
memory: 3856kb
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: 0ms
memory: 3608kb
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: 0ms
memory: 3648kb
input:
10 692137 743219 52652 45276 492360 972264 988496 117515 917868 423315
output:
415
result:
wrong answer 1st lines differ - expected: '521', found: '415'