public static BigInteger Get_Remainder_2dnm1(BigInteger bs, BigInteger d, BigInteger n, BigInteger f)
{
BigInteger triangle = Triangle(bs);//Tbs
BigInteger eight_base = BigInteger.Multiply(triangle, eight);//8Tbs
BigInteger XPN = BigInteger.Add(eight_base, one);//8Tbs+1
BigInteger two_d = BigInteger.Add(d, d);//2d
BigInteger nm1 = BigInteger.Subtract(n, one);//(n-1)
BigInteger two_d_nm1 = BigInteger.Multiply(two_d,nm1);//2d(n-1)
BigInteger XPN_mfp1 = BigInteger.Subtract(XPN, BigInteger.Subtract( f,one));//(x+n)(x+n) - (f-1)
BigInteger resultpN = BigInteger.Subtract(XPN_mfp1, two_d_nm1);//(x+n)(x+n) - (f-1) - 2d(n-1)
BigInteger result = BigInteger.Subtract(resultpN, BigInteger.Multiply(n,n));//(x+n)(x+n) - (f-1) - 2d(n-1) - nn
return result;
}