Description

【JZOJ B组】喝喝喝_题解

Input

【JZOJ B组】喝喝喝_C_02

Output

【JZOJ B组】喝喝喝_C_03

Sample Input

3 2
5 3 1

Sample Output

4

Data Constraint

【JZOJ B组】喝喝喝_C_04

思路

【JZOJ B组】喝喝喝_C_05

代码

#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);
}