比赛 |
20161115 |
评测结果 |
WWAWAWAAAA |
题目名称 |
军队 |
最终得分 |
60 |
用户昵称 |
1azyReaper |
运行时间 |
0.177 s |
代码语言 |
C++ |
内存使用 |
15.57 MiB |
提交时间 |
2016-11-15 10:51:36 |
显示代码纯文本
- #include <iostream>
- #include <fstream>
- #include <cstring>
- #include <cstdio>
- #include <algorithm>
- #include <cmath>
- #define ll long long
- #define max 1000001
- using namespace std;
- /* run this program using the console pauser or add your own getch, system("pause") or input loop */
- ll n,k,p[max],c[max];
- inline ll read()
- {
- char tmp=getchar();
- ll ans=0,f=1;
- while(tmp<'0'||tmp>'9')
- {
- if(tmp=='-')
- f=-f;
- tmp=getchar();
- }
- while(tmp>='0'&&tmp<='9')
- {
- ans=ans*10-'0'+tmp;
- tmp=getchar();
- }
- return ans*f;
- }
- inline ll gcd(ll x,ll y)
- {
- if(y==0)
- return x;
- else
- return gcd(y,x%y);
- }
- ll work()
- {
- ll ans=0,ft=1;
- for(int i=1;i<=n;i++)
- {
- for(int j=i-1;j>=ft;j--)
- {
- if(gcd(p[j],p[i])>1)
- {
- ft=j+1;
- break;
- }
- if(c[i]-c[ft-1]>=k&&i-ft+1>=ans)
- {
- ans=i-ft;
- }
- }
- }
- printf("%lld\n",ans);
- }
- int main(int argc, char** argv)
- {
- freopen("tarmy.in","r",stdin);
- freopen("tarmy.out","w",stdout);
- n=read();
- k=read();
- for(ll i=1;i<=n;i++)
- {
- p[i]=read();
- c[i]=c[i-1]+p[i];
- }
- work();
- return 0;
- }