标签: modulo

这是什么意思?expr1 = expr2 Mod expr3 = 0

所以我将一个VBA应用程序移植到PHP并遇到了这个奇妙的小块代码:

expr1 = expr2 Mod expr3 = 0
Run Code Online (Sandbox Code Playgroud)

我认为它的表现就像一个三元运算符,但是当我把它简化为简单的话,如果那么陈述结果并不像预期的那样.因此,我要求精彩的堆栈溢出社区帮助我,并将其置于易于理解的术语中.我知道通过查看其他答案,我不会失望.[/ end brown_nose>]

php vba modulo ternary

1
推荐指数
2
解决办法
1273
查看次数

1
推荐指数
1
解决办法
3204
查看次数

来自非常大的int C#的模数

我遇到了来自int的modulo的问题,它有31个字符.这似乎对错误进行
Int64 convertedNumber = Int64.Parse(mergedNumber);Value was either too large or too small for an Int64. (Overflow Exception).如何修复它以便modulo不会出错?

class GeneratorRachunkow {
    private static string numerRozliczeniowyBanku = "11111155"; // 8 chars
    private static string identyfikatorNumeruRachunku = "7244"; // 4 chars
    private static string stalaBanku = "562100"; // 6 chars

    public static string generator(string pesel, string varKlientID) {      
        string peselSubstring = pesel.Substring(pesel.Length - 5); // 5 chars (from the end of the string);
        string toAttach = varKlientID + peselSubstring;
        string …
Run Code Online (Sandbox Code Playgroud)

c# modulo c#-4.0

1
推荐指数
1
解决办法
4815
查看次数

当 `if (variable % 2 == 0)` 时程序崩溃

我正在编写一个可以找到完美数字的程序。阅读完这些完美数后,我发现了它们的列表:完美数列表。目前的输出是:

28         // perfect
496        // perfect
8128       // perfect
130816     // not perfect
2096128    // not perfect
33550336   // perfect
Run Code Online (Sandbox Code Playgroud)

我决定创建数组并将其与数字一起放置,将数字完全分开(没有其余部分)。因此,我将能够通过添加数组的所有元素来验证它是否是一个完美的数字。但应用程序崩溃了,我不明白为什么:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    unsigned long number;
    unsigned long arr2[100] = {0};
    int k = 0;

    for ( number = 0; number <= 130816; number++ )
        if ( 130816 % number == 0 )
            arr2[k++] = number;

    for ( k = 0; k < 100; k++ ) …
Run Code Online (Sandbox Code Playgroud)

c crash modulo undefined-behavior perfect-numbers

1
推荐指数
1
解决办法
1128
查看次数

haskell 中负整数的除法规则是什么?

在 GHCI 中,我得到以下结果:

div (-7) ( 2) = -4
div ( 7) (-2) = -4
div (-7) (-2) =  3

mod ( 7)  ( 2) =  1
mod ( 7)  (-2) = -1
mod (-7)  ( 2) =  1
mod (-7)  (-2) = -1
Run Code Online (Sandbox Code Playgroud)

并且div 4 (-3)-2并且mod 4 (-3)-2

我无法理解如何获得这些结果。有什么法律或规则吗?什么是正确的计算步骤?

haskell division modulo

1
推荐指数
1
解决办法
267
查看次数

Python While循环,也使用模和继续命令

尝试完成要求我执行以下任务的任务:

“编写一个while循环,该循环计算1到20(含)之间的整数之和,不包括那些被3整除的整数。(提示:您会发现模运算符(%)和continue语句很方便。)

我尝试自己构造代码,但是对代码的评估超时。我猜我的语法不正确并导致无限循环

    total, x = 0, 1
    while x >=1 and x <= 20:
        if x%3==0:
            continue
        if x%3 != 0:
            print(x)
            x+=1
            total+=1
    print(total)
Run Code Online (Sandbox Code Playgroud)

预期的答案应该是:

20 19 17 16 14 13 11 10 8 7 5 4 2 1

但是我只是收到“超时”错误

***最新::

尝试这样做:

total, x = 0, 1
while x>=1 and x<=20:
    if x%3 == 0:
        x+=1
        continue
    if x%3 != 0:
       print(x)
       x+=1
       total=+1
print(total)
Run Code Online (Sandbox Code Playgroud)

收到此::

Traceback (most recent call last):
   File "/usr/src/app/test_methods.py", line 23, in test
    self.assertEqual(self._output(), …
Run Code Online (Sandbox Code Playgroud)

python continue modulo while-loop

1
推荐指数
1
解决办法
149
查看次数

在 c 中计算非常大的数字

我是编程新手。我想计算一个范围内的数字的模数[0,10^24]。例如:(12 * 10^22) % 89 我知道我不能用像 long、integer 等通常的数据类型来做到这一点。我怎样才能做到这一点?有没有办法做到这一点?

提前致谢

c math modulo

1
推荐指数
1
解决办法
288
查看次数

( (value_in_dictionary) modulo[%] (dictionary) ) 在 Python 中有什么作用?

我想了解有什么value_in_dictionary % dictionary作用。

我试过

values = {
    'hello':'world',
    'hello2':'world2',
}
value = 'world'
print(value % values)
Run Code Online (Sandbox Code Playgroud)

这打印

world
Run Code Online (Sandbox Code Playgroud)

python dictionary modulo string-interpolation python-3.x

1
推荐指数
1
解决办法
110
查看次数

自定义货币系统乘法

我还在学习,所以放轻松。

我有以下货币系统:

3 种不同的硬币,我们称它们为玫瑰红(红色)、达拉宁(金色)和熟食(灰色)。100 Delis 等于 1 Daranen,100 Daranen 等于 1 Rhodonite。玫瑰石没有限制。

所以我试图将该货币乘以双倍系数。这是我的功能:

    public static Price multiply(Price price, double factor) {
       int de = (int)Math.round(price.getDelis() * factor);
       int da = (int)Math.round(price.getDaranen() * factor);
       int r = (int)Math.round(price.getRhodoniten() * factor);
       if ((de / 100) >= 1) {
           de = de % 100;
           da += de / 100;
       }
       if ((da / 100) >= 1) {
           da = da % 100;
           r += da / 100;
       }
       return new Price(r, da, de); …
Run Code Online (Sandbox Code Playgroud)

java multiplication modulo

1
推荐指数
1
解决办法
53
查看次数

'%'%'%' 是什么意思,为什么它等于 0?

以下程序:

int main()
{
    printf("%d", '%'%'%');
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

产生输出:

0
Run Code Online (Sandbox Code Playgroud)

我想知道这是什么原因。

c char modulo

1
推荐指数
1
解决办法
153
查看次数