模如何处理也小于除数的负红利?

问题描述 投票:1回答:3

为清楚起见,我了解以下三种情况下的模数行为。

我理解为什么16%3 = 1。

我了解为什么-16%3 =2。(我知道这可能很棘手)

我理解为什么3%16 = 3。

但是我不明白为什么-3%16 =13。我也不明白为什么有些在线资源(和某些编程语言)给出的答案是-3。我是一个初学者,所以实际的回答对我来说最有用。谢谢!

python math modulo
3个回答
1
投票

在python模数中将使用此方法获得结果

mod(a,n) = a - {n * Floor(a/n)}

因此,如果它是-3%16,它将像这样:

mod(-3,16) = -3 - {16 * Floor(-3/16)}
           = -3 - {16 * Floor(-0.1875)}
           = -3 - {16 * -1}
           = -3 - (-16)
           = 13

请检查一下很好的解释here


0
投票
仔细观察,就这么简单。您的问题如下:-为什么-3%16 = 13?在开始回答您的问题之前,请注意以下几点。2> 0 | -2 -1 | -2 -2 | -2 = -22> -3 | -2还要注意,<这是您的问题的答案。立即,您将如何思考?根据大学数学对您的问题的解释,希望您对加模和乘法模有知识:您的问题属于乘法模。基于概念理解的分析答案:16)-03(-1-16符号转换:(+)-------------------------------------03 + 16 = 13------------------------------------如果您对在概念上理解数学感兴趣并且熟悉,请参阅学位数学教科书,其中包含群论和向量论中的加法模和乘法模的概念。在那些教科书中,模数看起来像这样:A + k BA-k BA * k Bk称为整数集上的各个模数范围。A和B是执行执行的操作数。如果您一定会参考这些书,那么您将具有如何数学计算模数的基础知识。您仍然面临任何问题,请随时对我的回答发表评论。
    >>> # ******************
    >>> # Technical Answer:-
    >>> # ******************
    >>> x = -3
    >>> x
    -3
    >>> y = 16
    >>> y
    16
    >>> x % y
    13
    >>> # is same as follows:-
    >>> z = x % y
    >>> z
    13
    >>> # only the difference between the previous answer and this answer is as follows:-
    >>> # if you use like x % y as the above, whenever you require the resultant value of this computation for further actions (if applicable), you must always perform this task. Otherwise, Python Interpreter raises either ValueError or NameError based on the context of the logical code.
    >>> # if you use like z = x % y as the above, and you also require the computational value, then you just call the object z itself, automatically it gets the result of the operation x % y. Also you can reuse it any number of times.


-1
投票
要计算就可以使用
© www.soinside.com 2019 - 2024. All rights reserved.