其实就是等差数列求和,关键是注意项数怎么得到
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
int n,m,k;
while(scanf("%d%d%d",&n,&m,&k) != EOF)
{
//项数
int num = (m-n)/k+1;
//等差数列求和
int sum = n*num+((num*(num-1)*k)>>1);
printf("%d\n",sum);
}
return 0;
}