Questions tagged [modular-arithmetic]

Modular arithmetic is quite a useful tool in number theory. In particular, it can be used to obtain information about the solutions (or lack thereof) of a specific equation.

In mathematics, modular arithmetic (sometimes called clock arithmetic) is a system of arithmetic for integers, where numbers "wrap around" upon reaching a certain value—the modulus. The modern approach to modular arithmetic was developed by Carl Friedrich Gauss in his book Disquisitiones Arithmeticae, published in 1801.

Time-keeping on this clock uses arithmetic modulo 12. A familiar use of modular arithmetic is in the 12-hour clock, in which the day is divided into two 12-hour periods. If the time is 7:00 now, then 8 hours later it will be 3:00. Usual addition would suggest that the later time should be 7 + 8 = 15, but this is not the answer because clock time "wraps around" every 12 hours; in 12-hour time, there is no "15 o'clock". Likewise, if the clock starts at 12:00 (noon) and 21 hours elapse, then the time will be 9:00 the next day, rather than 33:00. Since the hour number starts over after it reaches 12, this is arithmetic modulo 12. 12 is congruent not only to 12 itself, but also to 0, so the time called "12:00" could also be called "0:00", since 0 ≡ 12 mod 12.

324 questions
-3
votes
1 answer

Square number multiple times

I'm looking for a way to square a number n, x times and get the answer in modulo m (m is prime)? For example, if n = 5, x = 3 and m = 7, it would be (((5^2)^2)^2) % 7 = 390625 % 7 = 4 I tried exponentiation by squaring (I have a function called…
-3
votes
2 answers

Find a,b,n so that (a^b)%n=x

Say I choose a value for x that can be between 0 and 2147483647. (Int32.MaxValue) I am trying to figure out how I can find values for a,b,n so that (a^b)%n=x I already know that I can use ModPow to verify the values, but I don't know how I can find…
Kyu96
  • 1,159
  • 2
  • 17
  • 35
-3
votes
1 answer

Computing (a^x)mod n using addition chaining. Algorithm in C++

unsigned long qe2(unsigned long x, unsigned long y , unsigned long n) { unsigned long s,t,u; s=1; t=x; u=y; while(u) { if(u&1) s = (s*t)%n; u>>=1; t= ( t*t)%n; } return s; } I was readin…
-3
votes
2 answers

Least Non-Negative Residue: Large Numbers

I am trying to build a C++ program that can solve the modular congruence: n^p = x (mod q ), where n is a small number, and p and q are very large arbitrary primes. I've tried to do this multiple times, but I always run into memory overflow issues.…
Trancot
  • 1,509
  • 2
  • 11
  • 10
-4
votes
1 answer

How to convert a modular arithmetic equation to python code?

(x/y) mod n = ((x mod n) * (y mod n)^-1) mod n I would like to know how to convert the above statement into python.
-4
votes
1 answer

C++ Number theory: Fastest way to compute max(y = a_i * x+ b_i) <= k

following Problem, when having to make a fast code: I have a list of 2 integers a_i and b_i and I have to compute the equation: y = (a_i * x + b_i), where I'm only interested in y, not in x. All a_i's are prime and different from each other. a_i = y…
-4
votes
3 answers

Java BigInteger , number theory , modular arithmetic

Anyone have an idea on how to implement such a problem in java ? "Implement a subroutine that takes three positive integer arguments (a; b; n) and returns the value of ( (a to the power of b) mod n), where the arguments are represented by about 100…
-4
votes
1 answer

Hash and Modular Arthmetic

Let h(y) be the function defined as (a*y+b)mod m. So h(y) can take values from 0 to m-1. Now we are given 7 integers- a,b,x,n,c,d,m. Our task is to find the total count of h(x),h(x+1),h(x+2)...h(x+n) such that the value of h(x+i) falls in the range…
-5
votes
2 answers

Anyone understand what these instructions are asking, and know how to write this in assembly?

Problem- Using the Intel86 simulator, given three one-byte numbers X, Y and Z (1
1 2 3
21
22