记录编号 350419 评测结果 AAAAAAAAAA
题目名称 军队 最终得分 100
用户昵称 Gravatarjinqiu 是否通过 通过
代码语言 C++ 运行时间 0.124 s
提交时间 2016-11-15 19:23:54 内存使用 1.46 MiB
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;

const int maxn = 1e5 + 10;
int n, ans, m;
int a[maxn]; 
LL sum[maxn];

int gcd(int, int);
int read();

int main() {
	freopen("tarmy.in", "r", stdin);
	freopen("tarmy.out", "w", stdout);
	int i;
	n = read(); m = read();
	for(i = 1; i <= n; i++) {
		a[i] = read();
		sum[i] = sum[i - 1] + a[i];
	}
	int l = 1,  r = 1;
	while(r <= n) {
		bool flag = true;
		int sign = 0;
		while(flag) {
			r++;
			for(i = r - 1; i >= l; i--) {
				if(gcd(a[i], a[r]) != 1) {
					sign = i;
					flag = false;
					break;
				}
			}
		}
		if(sum[r - 1] - sum[l - 1] >= m)
			ans = max(ans, r - l);
		l = sign + 1;
	}
	cout << ans << "\n";
	return 0;
}

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}

int read() {
	char s = getchar();
	int t = 0, f = 1;
	while(!isdigit(s)) {
		if(s == '-')f = -1;
		s = getchar();
	}
	while(isdigit(s)) {
		t = (t << 3) + (t << 1) + s - '0';
		s = getchar();
	}
	return t*f;
}