比赛 20161115 评测结果 AAAAAAAAAA
题目名称 军队 最终得分 100
用户昵称 Fmuckss 运行时间 0.335 s
代码语言 C++ 内存使用 11.44 MiB
提交时间 2016-11-15 11:41:53
显示代码纯文本
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
const int maxn = 1e6;
const int top = 2e5;

#define is_num(x) (x <= '9' and x >= '0')
inline LL get_num() {
	char tmp = getchar();
	int res = 0;
	
	while (not is_num(tmp)) tmp = getchar();
	while (    is_num(tmp)) {
		res = (res << 3) + (res << 1) + tmp - '0';
		tmp = getchar(); 
	}
	
	return res;
}

int prime[maxn], pcnt;
bool isn_prime[maxn];

inline void get_prime() {
	for (int i = 2; i <= top; i++) {
		if (not isn_prime[i]) prime[++pcnt] = i;
		
		for (int j = 1; j <= pcnt and prime[j] * i <= top; j++) {
			isn_prime[prime[j] * i] = true;
			
			if (not (i % prime[j]))
				break;
		} 
	}
}

int s[maxn], n, k;

inline void read() {
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++) s[i] = get_num();
}

int cnt_num[maxn];
int stop;


inline bool handle(int pos, bool dehandle = false) {
	int num = s[pos];
	bool is_ok = true;
	
	for (int i = 1; prime[i] * prime[i] <= num and i <= pcnt and num != 1; i++) {
		if (dehandle and cnt_num[prime[i]] == 2 and (not (num % prime[i]))) --stop;
		if (not dehandle and cnt_num[prime[i]] == 1 and (not (num % prime[i]))) ++stop;
		
		if (not (num % prime[i])) cnt_num[prime[i]] += dehandle ? -1 : 1;
		while (not (num % prime[i])) num /= prime[i];
	} 
	
	if (num != 1) {
		if (dehandle and cnt_num[num] == 2) --stop;
		if (not dehandle and cnt_num[num] == 1) ++stop;
		cnt_num[num] += dehandle ? -1 : 1;
	}
	
	return stop == 0;
}

inline void solve() {
	int l = 1, ans = 0;
	long long now_sum = 0;
	bool statu = false;
	
	for (int i = 1; i <= n; i++) {
		statu = handle(i);
		now_sum += s[i];
		
		while (not statu) now_sum -= s[l], statu = handle(l++, true);
		if (statu and now_sum >= k) ans = max(ans, i - l + 1);
	}
	
	printf("%d\n", ans);
}

int main() {
	freopen("tarmy.in", "r", stdin);
	freopen("tarmy.out", "w", stdout);
	read();
	get_prime();
	solve();
	return 0;
}