C:

枚举中间点,计算两边点差值,把个数乘起来即可

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=200005;
long long n,k,ans;
int main()
{
scanf("%lld%lld",&n,&k);
for(long long i=1;i<=n;i++)
if(2*(abs(k-i)%k)%k==0)
ans+=1ll*((n-(abs(k-i)%k))/k+(abs(k-i)%k!=0))*((n-(abs(k-i)%k))/k+(abs(k-i)%k!=0));//,cerr<<i<<" "<<(n-(abs(k-i)%k))/k<<endl;
printf("%lld\n",ans);
return 0;
}

D:

ARC102 C~D-LMLPHP

#include<iostream>
#include<cstdio>
using namespace std;
const int N=20005;
long long n,k,w,k1,t,cnt,p,p1[N],kl[N],l[N],r[N],v[N];
int main()
{
scanf("%d",&n);
k=1;
if(n==1)
{
printf("2 1\n1 2 0\n");
return 0;
}
t=1;
while(t*2<=n)
{
l[++cnt]=k;
r[cnt]=k+1;
v[cnt]=0;
l[++cnt]=k;
r[cnt]=k+1;
v[cnt]=t;
k++;
t=t*2;
}
k1=k;
n=n-t;
w=t;
while(n>0)
{
t=1;
k=1;
while(t*2<=n)
t=t*2,k++;
l[++cnt]=k;
r[cnt]=k1;
v[cnt]=w;
w=w+t;
n=n-t;
}
printf("%d %d\n",k1,cnt);
for(int i=1;i<=cnt;i++)
printf("%d %d %d\n",l[i],r[i],v[i]);
return 0;
}
05-25 21:30