Questions tagged [mod]

For questions related with the *mod operation*, that can arise in Cryptography, Number Theory, Hashing, etc..

In computing, the modulo operation finds the remainder after division of one number by another (sometimes called modulus). Given two positive numbers, a (the dividend) and n (the divisor), a modulo n (abbreviated as a mod n) is the remainder of the Euclidean division of a by n.

437 questions
2
votes
1 answer

Modulo simplification in coq

I am a beginner at Coq and I'm stuck at a problem in Coq, I am not able to simplify this further. It would be great if anyone had any tips on how to break the problem down into smaller steps. The lemma is this: forall (n : N) (n0 : N), ((1 + 2 * n…
2
votes
2 answers

Make Folding an ArrayList to single integer

I'm Developing a Code for java to Fold the element inside an array with example A[0] = 2, A[1] = 7, A[2] = 9, A[3] = 7 Then Fold it with this format A[0] = (A[0] + A[3]) mod 10 = 9 A[1] = (A[1] + A[2]) mod 10 = 6 And Fold it again until single A[0]…
Al_Muzakier
  • 49
  • 1
  • 9
2
votes
2 answers

Google Sheets: Average of every other column

I’ve looked at similar questions and I think I’m close to a working solution, but it’s giving me the wrong answer. I have a spreadsheet in Google Sheets with data in all columns, but every other cell contains a dollar value and I need only the…
jondesu
  • 23
  • 5
2
votes
2 answers

Haskell mod malfunction?

Here is my Haskell function to remove 2::Int and 5::Int from a list: remPrimesFactors25 :: [Int] -> [Int] remPrimesFactors25 [] = [] remPrimesFactors25 (x:xs) | x == 2 = remPrimesFactors25 xs | x == 5 =…
user7629669
2
votes
1 answer

Extend Euclid Algorithm with matrix inverse mod N

I am implementing an extended Eucilid algorithm with matrix mod N. This is my code implementation: def eea(a, b): if not isinstance(a, int) or not isinstance(b, int) or not a or not b: result = 'Error(eea): Invalid input num' else: …
余星佑
  • 71
  • 8
2
votes
2 answers

Replacing specific values in an array based on logic

I'm trying to replace the values in array1 following this Logic: If the values are greater than one use just the decimal value. If it's exactly 1 stay at 1 If 0 stay 0 If neg make positive and follow the logic The code I used was: array1=[0.5 1.3…
Rick T
  • 3,349
  • 10
  • 54
  • 119
2
votes
4 answers

Checking if two three digit numbers have any of there digits that are the same in Java

I'm trying to write a program in Java that checks if at least one digit of one of the numbers, matches one digit of the other number. For example, if the two numbers are 238 and 345 it should return a certain string. So far this is what I have, but…
2
votes
2 answers

Solving modular linear congruences for large numbers

I'm looking for a better algorithm than one I found on stackoverflow to handle 4096 byte numbers, i'm hitting a maximum recursion depth. Code from stackoverlow post, i copy/pasted it but lost the original link: def linear_congruence(a, b, m): if…
oppressionslayer
  • 6,942
  • 2
  • 7
  • 24
2
votes
2 answers

decimal value of the number formed by concatenating the binary representations of first n natural numbers

Given a number n, find the decimal value of the number formed by concatenating the binary representations of first n natural numbers. Print answer modulo 10^9+7. Also, n can be as big as 10^9 and hence logarithmic time approach is needed. Eg: n=4,…
karthick M
  • 192
  • 1
  • 13
2
votes
1 answer

Angle math, normalize to [-180,180] and mod vs remainder()

I need to convert a double/float angle to the range of [-180,180] by adding or subtracting 360. The remainder function works, but I am not sure why. x = remainder (x, 360); Why does this produce a range of [-180,180] and not [0,359.99999...]? I…
Trygve
  • 1,317
  • 10
  • 27
2
votes
1 answer

Repeating numbers with modulo -1 to 1 using positive and negative numbers

Repeating numbers with modulo I know I can "wrap" / loop numbers back onto themselves like 2,3,1,2,3,1,... by using modulo. Example code below. a=[1:8]' b=mod(a,3)+1 But how can I use modulo to "wrap" numbers back onto themselves from -1 to 1 …
Rick T
  • 3,349
  • 10
  • 54
  • 119
2
votes
1 answer

Trouble converting a modulus pow() function from Lua to Python

I have tried to rewrite a Lua mod_pow() function ( which works ) to Python. The syntax and everything looks ok to me so I'm not sure what I'm missing. Does anyone know what I need to change in my Python code to get it to work and give 81 as the…
oppressionslayer
  • 6,942
  • 2
  • 7
  • 24
2
votes
1 answer

How to solve for y in formula (y*known_number)%145 = 81 without a loop

Is it possible to solve for y in this equation without a loop? known_number = 7 (y * known_number) % 145 == 81 I'm using a loop, but i'm thinking since it's simple multiplication, there may be a formula that can be used to solve it without a loop,…
oppressionslayer
  • 6,942
  • 2
  • 7
  • 24
2
votes
1 answer

Best option to split a column into 2, 3, 4, 5 or more columns

I have this formula to split a column into two columns: =ArrayFormula( IFERROR(HLOOKUP(1,{1;**COLUMN TO DIVIDE**}, (ROW(A:A)+1)*2-TRANSPOSE(sort(ROW(A1:A2)+0,1,0))))) I would like to know if there is a better way to do this and if there is a way to…
2
votes
0 answers

Conversion between uint64_t to mpz_t

This code work perfectly for modular exponentiation. But i want this to input and unsigned int(uint64_t) and get result in same type(uint64_t). int main() { uint64_t x = 1103362698; uint64_t y = 137911680; uint64_t z = 1217409241131113809; …
superstack
  • 91
  • 5