比赛 |
20161115 |
评测结果 |
AAAAAAAAAT |
题目名称 |
军队 |
最终得分 |
90 |
用户昵称 |
Rapiz |
运行时间 |
4.577 s |
代码语言 |
C++ |
内存使用 |
2.24 MiB |
提交时间 |
2016-11-15 11:30:56 |
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <algorithm>
#define file(x) "tarmy." #x
typedef long long ll;
using std::max;
const int UPB = 1e6, SZ = 8e4, N = 1e5 + 10;
int n, k, a[N], sz, pt[SZ], ans, nl = 1, ext[SZ], upb;
ll sum;
bool ip[UPB];
int main() {
freopen(file(in), "r", stdin);
freopen(file(out), "w", stdout);
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]), upb = max(upb, a[i]);
memset(ip, 1, sizeof(ip));
for (int i = 2; i <= upb; i++) if(ip[i]) {
pt[++sz] = i;
for (int j = i + i; j <= upb; j+= i) ip[j] = 0;
}
for (int i = 1; i <= n; i++) {
sum += a[i];
int x = a[i], ll = nl;
for (int j = 1; j <= sz && pt[j] <= x; j++) if(x%pt[j] == 0){
nl = max(nl, ext[j] + 1);
while(x%pt[j] == 0) x/=pt[j];
}
for (int k = ll; k < nl; k++) {
sum -= a[k];
int x = a[k];
for (int j = 1; j <= sz && pt[j] <= x; j++) if(x%pt[j] == 0) {
ext[j] = 0;
while(x%pt[j] == 0) x/=pt[j];
}
}
x = a[i];
for (int j = 1; j <= sz && pt[j] <= x; j++) if(x%pt[j] == 0) {
ext[j] = i;
while(x%pt[j] == 0) x/=pt[j];
}
if (sum >= k) {
//if (i - nl + 1 > ans) printf("%d %d\n", nl , i);
ans = max(ans, i - nl + 1);
}
}
printf("%d", ans);
}