# |
Author |
Problem |
Lang |
Verdict |
Time |
Memory |
Sent |
Judged |
|
257480466 |
Practice:
daobao27 |
1609C
- 48
|
C++17 (GCC 7-32)
|
Accepted
|
702 ms
|
16 KB
|
2024-04-20 22:50:29 |
2024-04-20 22:50:29 |
|
#include <bits/stdc++.h>
#define ll long long
using namespace std;
bool prost(int n){
if(n==1) return false;
for(int i=2;i*i<=n;i++)
if(n%i==0) return false;
return true;
}
int main(){
int t; cin>>t;
while(t--){
int n,k; cin>>n>>k;
int a[n];
long long s=0;
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++){
if(prost(a[i])){
long long r=1,l=1;
while(r*k+i<n&&a[r*k+i]==1) r++;
while(i-l*k>=0&&a[i-l*k]==1) l++;
l--;r--;
s+=l+r+l*r;
}
}
cout<<s<<endl;
}
return 0;
}
Click to see test details