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...

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 ...
Postilion asked 28/11, 2015 at 12:19

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 ...
Gerah asked 4/7, 2009 at 20:22

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...
Piselli asked 25/3, 2017 at 15:26

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?
Tiflis asked 15/12, 2011 at 2:54

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...
Amaryl asked 15/3, 2022 at 8:47

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: (...
Koeppel asked 23/11, 2017 at 11:56

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

I have one employee table which contains: emp id Sum ------ --- 1 7 2 6 I want a SQL query for getting the quotient and remainder when dividing the Sum with 8.
Quartus asked 9/4, 2011 at 6:21

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...
Bereft asked 12/10, 2014 at 8:29

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...
Anking asked 3/9, 2021 at 23:37

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&gt...
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?
Romanticist asked 13/12, 2010 at 18:31

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...
Certainly asked 2/4, 2010 at 9:54

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...
Tumid asked 28/7, 2021 at 16:47

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.