modulo Questions
5
Solved
My problem is to compute (g^x) mod p quickly in JavaScript, where ^ is exponentiation, mod is the modulo operation. All inputs are nonnegative integers, x has about 256 bits, and p is a prime numbe...
Jolie asked 20/9, 2009 at 8:48
15
Solved
Am I doing modulus wrong? Because in Java -13 % 64 evaluates to -13 but I want to get 51.
Opinionated asked 9/12, 2010 at 21:57
13
Solved
I'm trying to sort the digits of an integer of any length in ascending order without using Strings, arrays or recursion.
Example:
Input: 451467
Output: 144567
I have already figured out how to ...
15
I'm trying to mod an integer to get an array position so that it will loop round. Doing i %
arrayLength works fine for positive numbers but for negative numbers it all goes wrong.
4 % 3 == 1
3 ...
1
I am searching for a very CPU efficient way to compute floating point modulus one (including negative values) in C. I am using it for normalized phase reduction (wrapping, i.e 7.6 -> 0.6, 0.2-&g...
Destine asked 14/8, 2022 at 11:29
5
I am learning Go and I come from a Python background.
Recently, I stumbled onto a behaviour of the %(modulo) operator which is different from the corresponding operator in Python. Quite contrary to...
5
Solved
Is it possible to use numpy's linalg.matrix_power with a modulo so the elements don't grow larger than a certain value?
3
Solved
For a homework assignment, I need to return the remainder after dividing num1 by num2 WITHOUT using the built-in modulo (%) operator. I'm able to get most tests to pass with the following code, but...
Dafna asked 9/3, 2017 at 16:34
1
I don't mean a tiny precision error, I mean a completely "wrong" result, for a harmless-looking calculation:
expected: 1.7306687640440686
got: 0.08453630115074517
The calculation (Try it...
Sophocles asked 31/5, 2022 at 17:32
6
Solved
I'm trying a line like this:
for i in {1..600}; do wget http://example.com/search/link $i % 5; done;
What I'm trying to get as output is:
wget http://example.com/search/link0
wget http://exampl...
Shivery asked 16/4, 2011 at 18:21
3
Solved
I am a computer science student; I am studying the Algorithms course independently.
During the course, I saw this question:
Given an n-bit integer N, find a polynomial (in n) time algorithm that d...
13
Solved
According to Google Calculator (-13) % 64 is 51.
According to JavaScript, it is -13.
console.log(-13 % 64);
How do I fix this?
Thiamine asked 17/12, 2010 at 3:55
2
I previously incorrectly thought that the % operator returned the remainder and the mod operator returned the modulus (the remainder and modulus are the same when the operands are both positive or ...
Chateau asked 10/2, 2022 at 15:14
4
Solved
In Kotlin I have seen that for function a.mod(n), if a is negative the result is negative. Which is not what modulo is supposed to do. What can I do to have always positive modulo?
For example:
(...
17
I'm looking for an explanation of how a hash table works - in plain English for a simpleton like me!
For example, I know it takes the key, calculates the hash (I am looking for an explanation how...
Reversion asked 8/4, 2009 at 15:48
2
Solved
Golang's math.Mod(10, 4) returns 2 -- ie. the integer part of division result 2.5 -- but shouldn't it be "the floating point remainder", that is, 0.5?
Schwitzer asked 18/5, 2012 at 9:32
2
According to Wikipedia, the modulo operator (remainder of integer division) on n should yield a result between 0 and n-1.
This is indeed the case in python:
print(-1%5) # outputs 4
In Ruby:
pu...
Erastatus asked 19/11, 2016 at 10:53
6
3
I am seeking for a way to find modulo of a sequence of numbers like:
(a1 + a2 + a3 + a4 + ... + an) mod x
Is there any way/property of modulo function so that I can compute mod of this sequence fr...
1
x86 and likely other architectures provide a method to get the quotient and remainder in a single operation (DIV). Because of this many languages have a DIVMOD combined operation, (like DIVREM in C...
1
Solved
As an exercism exercise, I'm currently trying to filter an iterator according to whether the value is even in order to produce a new iterator.
My function currently looks like:
pub fn evens<T>...
Wardwarde asked 2/9, 2021 at 14:48
20
Solved
What does the % do in a calculation? I can't seem to work out what it does.
Does it work out a percent of the calculation for example: 4 % 2 is apparently equal to 0. How?
15
Solved
I have a 128-bit unsigned integer A and a 64-bit unsigned integer B. What's the fastest way to calculate A % B - that is the (64-bit) remainder from dividing A by B?
I'm looking to do this in eith...
5
Solved
Suppose I have a vector x with n elements. I want to use any vectorised function, say cumprod, on every alternate number of x, i.e. every 1, 3, 5 and so on and another on 2, 4, 6 and so on. I am ad...
2
Solved
I am writing some assembly code for ARM8 (aarch64). I want to do a division and use the remainder obtained for further calculations. In x86 when I use
'div', and I know my remainder is kept in RDX...
Backbone asked 11/2, 2016 at 22:37
© 2022 - 2025 — McMap. All rights reserved.