Description
Input
Output
Sample Input
3 2
5 3 1
Sample Output
4
Data Constraint
思路
代码
#include<cstdio>
#include<iostream>
using namespace std;
int n,k,x,l=1,r[100010];
long long ans;
int main()
{
freopen("drink.in","r",stdin),freopen("drink.out","w",stdout);
scanf("%d%d",&n,&k);
for(int i=1; i<=n; i++)
{
scanf("%d",&x);
if(x>k) l=max(l,max(r[0],r[x])+1);
ans+=i-l+1ll,x-=k;
if(x<=0)
{
if(!x) r[0]=i;
continue;
}
for(int j=1; j*j<=x; j++) if(x%j==0) r[j]=r[x/j]=i;
}
printf("%lld",ans);
}