y*hZ}Xnd2G3^/
在线尝试!
由于数值精度,最后一个测试用例不会产生确切的整数。MATL的默认数据类型(double
)只能处理不超过的精确整数2^53
。
说明
y % Implicitly input [a; b] (col vector) and p (number). Push another copy of [a; b]
% Stack: [a; b], p, [a; b]
* % Multiply the top two elements from the stack
% Stack: [a; b], [a*p; b*p]
h % Concatenate horizontally
% Stack: [a, a*p; b, b*p]
Z} % Split along first dimension
% Stack: [a, a*p], [b, b*p]
Xn % Vectorize nchoosek
% Stack: [nchoosek(a,b), nchoosek(a*p,b*p)]
d % Consecutive differences of array
% Stack: nchoosek(a,b)-nchoosek(a*p,b*p)
2G % Push second input again
% Stack: nchoosek(a,b)-nchoosek(a*p,b*p), p
3^ % Raise to third power
% Stack: nchoosek(a,b)-nchoosek(a*p,b*p), p^3
/ % Divide top two elements from the stack
% Stack: (nchoosek(a,b)-nchoosek(a*p,b*p))/p^3
% Implicitly display
.0
在末尾,以真正表明该部门没有剩余。