问题标签 [number-theory]

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 投票
2 回答
269 浏览

haskell - Infinite lazy lists of digits

So I'm trying to do some number theory work, and I was using Mathematica but thought that Haskell would be more suited to dealing with infinite lists (as AFAIK Mathematica doesn't have lazy evaluation). What I want to do is have Haskell store all the digits of 1/x in an infinite lazy list. So far my searching has not turned up a way to split a ratio into its digits that returns a list of digits rather than an actual floating point number.

0 投票
2 回答
109 浏览

algorithm - Number theory: solution need

Suppose a = a31 a30 . . . a1 a0 is a 32-bit binary word.
Consider the 32-bit binary word b = b31 b30 . . . b1 b0 computed by the following algorithm:

  1. Scan a from right to left and copy its bits to b until the first 1 is found (which is also copied to b)
  2. After that, copy the Boolean negations of the bits in a.

For example, a = 10100 . . . 00 is transformed to b = 01100 . . . 00. Explain what this algorithm computes if a and b are interpreted as binary numbers.

0 投票
3 回答
709 浏览

matlab - 费马小定理在 MATLAB 中失败?

我目前正在尝试在 MATLAB 中编写一个程序来检查一个数字n是否为素数。对于初学者,我正在实施Fermat Primality Test

费马指出,对于素数p1 <= b < p

所以在 MATLAB 中p = 17,和b = 11

或者

我遇到的问题是,对于这种情况,MATLAB 返回0. 但是,如果p是素数,它应该返回1。我看不到我缺少什么,因此非常感谢任何帮助!

0 投票
2 回答
110 浏览

math - 乘法阶数与乘法组的阶数

如何证明所有乘法阶数除以F13的乘法群F的阶数(大小)。.

0 投票
2 回答
1643 浏览

arrays - 为什么数组大小必须为 3^k+1 才能使循环领导者迭代算法起作用?

循环领导迭代算法是一种通过将所有偶数条目移动到前面并将所有奇数条目移动到后面同时保留它们的相对顺序来对数组进行洗牌的算法。例如,给定这个输入:

输出将是

该算法在 O(n) 时间内运行并且仅使用 O(1) 空间。

该算法的一个不寻常的细节是它通过将数组拆分为大小为 3 k +1 的块来工作。显然这对于​​算法正常工作至关重要,但我不知道为什么会这样。

为什么算法中需要选择 3 k + 1?

谢谢!

0 投票
2 回答
184 浏览

combinatorics - 矩形网格的每一行或每一列的总和是偶数

假设一个矩形网格在每个正方形中填充了 0 和 1,这样对于每一行和每一列,数字的总和都是偶数。证明如果正方形像棋盘上一样是黑白的,那么黑色正方形上的数字有一个偶数和。

谁能给我一个提示?

0 投票
1 回答
3601 浏览

cryptography - 在 RSA 加密算法中查找 p 和 q

在 RSA 加密算法中,如何找到 和 的因数pqe已知的。我试图搜索但找不到任何来源。任何提示、参考或解决方案就足够了。dn

(e,n)(d,n)分别是公钥和私钥,n = pq.

0 投票
1 回答
61 浏览

number-theory - _REQUEST 只返回输入的第一个字母

我正在尝试通过表单(帖子)更新数据库中的记录,但是当我访问全局参数变量时,由于某种原因,仅返回原始输入的第一个字符。

0 投票
1 回答
857 浏览

assembly - 在没有扩展 euclid 算法的 RSA 加密中查找 d

我正在尝试使用汇编在 PIC16 微控制器中实现 RSA!
我写了一个数学库,可以执行加法、减法、乘法和模幂运算(都是无符号的)。

但现在我坚持找到满足以下条件的“d”的最后一步:
d*e = 1 (mod phi(n))
我想避免实现扩展的欧几里得算法,它有点复杂并且需要有符号的操作。

我尝试使用欧拉定理http://en.wikipedia.org/wiki/Modular_multiplicative_inverse#Using_Euler.27s_theorem
计算它, 但是我需要找到 phi(phi(n) 这是一个复杂的过程,除非 p 和 q 是安全的素数。

我剩下的唯一选择是循环 d=(KN+1)/e 同时改变 k 直到 (KN+1) mod e = 0
所以我现在的问题是:最后一个公式是计算 d 的唯一其他选择吗?
(如果没有)还有哪些其他选择?
K 的限制是什么?

0 投票
1 回答
485 浏览

java - 找到模结果的正确方法

众所周知,模运算求一个数除以另一个数的余数

我正在努力找出获得模值的正确方法。

a mod b = c

如果 a >= 0,很容易找到 c。但是,如果 a < 0,我会感到困惑。

有一天,如果-75 mod 26 = 3,我在我的讲师笔记中读到。

然后,我在java中创建了一个简单的程序来查找-75 mod 26的结果。程序编译并打印结果:-23。

那么,如果 a < 0,找到 c 的正确方法是什么?

下面是我尝试过的代码: