问题标签 [modulus]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
4 回答
671 浏览

java - 在java中,我想做 102%100 并将余数设为 02 而不是 2 .. 我该怎么做?

在java中,我想做 102%100 并将余数设为 02 而不是 2 .. 我该怎么做?

int a = (102%100);

a 返回 2 而不是 02.. 我想得到 02.. 因为最初,它应该是 1.02,但 mod 返回 2. :( 有人知道该怎么做吗?

0 投票
2 回答
3171 浏览

xpath - Xpath 将节点转换为 mod 的编号

我有包含我想转换为数字并使用 mod 的数字的节点。例如:

我试过了:

知道这是否可以做到吗?即使有办法转换为 ASCII,我也会接受

提前致谢!

0 投票
5 回答
1403 浏览

c++ - c中的模运算符

我需要检查 c 中数字的可分性。如何使用 C 中的模运算来检查一个数字是否可以被另一个数字整除?我试过这样做:

它不起作用,尽管 file_int 等于 9。

我做错了什么?

谢谢

0 投票
4 回答
127 浏览

c++ - 如果需要构造建议

我有一个 for 循环,我在其中放置了几个 if 语句。这些条件的目的是检查一个数的可整性,如果该数能被 3 整除,则输出一个字符串。如果该数能被 5 整除,则输出另一个字符串。但是,如果该数字可以被 3 和 5 整除,则会在其位置输出一个完全不同的字符串,而不是其他字符串。

这是我的代码:

如您所见,最后一个条件并不完全有效。我应该使用什么类型的控制结构?别的?

非常感谢。

0 投票
3 回答
6685 浏览

modulus - a/b mod m = (a mod m)/(b mod m) 吗?

有吗a/b mod m = (a mod m)/(b mod m)

我正在尝试为非常大的数字找到 nCr mod m。如果a/b mod m = (a mod m)/(b mod m)那时认为我会解决我的问题。

它适用于欧拉计划。我正在使用阶乘的 nCr 公式。

0 投票
2 回答
137 浏览

modulus - 如何找到 (2^n)%p 的结果?

我被困在一个要求找到 (2^n)%p 的问题中,其中 n 是 10^36 阶的一个非常大的数字,p 是一个素数。如何快速做到这一点?这里 ^ 表示我来的力量在这个算法中,但它会导致堆栈溢出,因为 10^36 非常大

他们有任何其他方式或对此有所改进吗?

0 投票
1 回答
146 浏览

c# - 模数 (%) 运算符的 CodeContracts 失败?

我正在编写一个专门的随机器类,并希望使用 CodeContracts 确保它的质量。典型的随机化器方法接收上限“最大值”并返回低于该限制的正随机值。

wherepick()返回一个随机数UInt32。我的问题:为什么 CodeContracts 在最后一个“确保”时失败?

0 投票
1 回答
160 浏览

php - PHP 溢出模数

我正在编写一个使用连续平方来求解 a^k mod m 的算法。由于连续平方的工作方式,算法必须计算的最大数字是 2147483646^2(我将用户输入限制为 214738364)。不幸的是,它仍然需要计算这个。它似乎正确地得到了平方部分,然后将溢出的数字转换为浮点数,但随后无法计算浮点数和整数的模数。

示例行是:

我该如何解决这个问题,以及如何在 PHP 中找到解决整数溢出的方法?

0 投票
2 回答
1193 浏览

.net - XSLT mod 检查大数

我正在尝试在 XSLT 1.0 中对 17 位数字进行模数 11 检查。但是,它似乎总是给出错误的输出。

我能找到的唯一信息是在这篇文章中,但是没有找到解决方案。

我过去曾为 Luhn 检查器使用 XSLT 模板,我意识到这与模数检查的工作方式不同,但我想知道是否有人知道可以计算大数模数的 XSLT 模板?

0 投票
2 回答
2729 浏览

java - How do I effectively use the Modulus Operator in Java

I am doing a college assignment in Java that deals with currency. For that I am advised to use ints instead of doubles and then later convert it to a dollar value when I print out the statement.

Everything works fine until I do calculations on the number 4005 (as in $40.05 represented as an int). I am pasting the part of code I am having problems with, I would appreciate if someone could tell me what I am doing wrong.

The above code, when run, shows $40.5, instead of $40.05. What gives?

Kindly note that this is for my homework and I want to learn, so I would really appreciate an explanation about the root of the problem here rather than just a simple solution.

EDIT: Following Finbarr's answer, I have added the following to the code which seems to have fixed the problem:

Is this a good way to do it or am I over-complicating things here?

EDIT: I just want to make it clear that it was both Finbarr and Wes's answer that helped me, I accepted Wes's answer because it made it clearer for me on how to proceed.