Sum of many ints

2017/12/23 posted in  codeWars

题目链接:https://www.codewars.com/kata/moves-in-squared-strings-i/train/objc

注意long long类型。

#import <Foundation/Foundation.h>

long long f(long long n, long long m) {
    long long sum = 0;
    long long q = n/m;
    long long p = n%m;
    sum+= (m*(m-1)/2)*q;
    sum+= (p+1)*p/2;
    return sum;
}