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
0
votes
1 answer

How to find n%(k*k) without integer overflow?

I know that (a*b)%m is equal to ((a%m)*(b%m))%m? But how to calculate a%(m*m)?
0
votes
1 answer

Circular Queue toString method ignoring some conditions

when I call my toString() method it doesn't work if after the index wraps around (front > rear). I have included the code below. After, I enqueue(5) and enqueue(6), the toString seems to be completely ignored. At first I thought I wasn't overriding…
0
votes
0 answers

I am having trouble solving a problem using modulo arithmetic

i need to apply modulus e=10^9+7 on the given expression i*(n+k-2)-((i*(i+1)*(n-1))/2) where i is in terms of n and k . n and k are inputted by the user. 2≤N≤10^18 1≤K≤10^18 i tried using modular arithmetic using the basics i.e …
0
votes
1 answer

How to find the base value in modular arithmetic?

I need an efficient formula of some kind that will allow one to figure out the original message(msg) with regards to the following formula: C = msg^e mod N. If a user is provided with C, e and N, is there an efficient way to calculate msg? In this…
James Foster
  • 71
  • 1
  • 7
0
votes
2 answers

What does the notation a (mod b, n) mean?

I'm trying to write a Python program for the AKS primality test. The 5th step states if (X+a)^n≠ X^n+a (mod X^r − 1,n), output composite; but I'm not sure what to do when the modulo has 2 arguments: Xr-1 and n. In this case, what is it supposed to…
Gimdalf
  • 67
  • 6
0
votes
1 answer

modular arithmetic puzzle codeforces

A car moves from point A to point B at speed v meters per second. The action takes place on the X-axis. At the distance d meters from A there are traffic lights. Starting from time 0, for the first g seconds the green light is on, then for the…
akacodes121
  • 129
  • 8
0
votes
0 answers

How to determine the full private key(d) of RSA from partially exposed private key, public key, and a plain text-cipher sample?

To be exact, I search google and couldn't find a solution for 3 days of the problem I am working with. Suppose we have the following data: n =…
Rahat Zaman
  • 1,322
  • 14
  • 32
0
votes
1 answer

Modular arithmetic. How to solve the following equation?

How to solve the following equation? I am interested in the methods of solutions. n^3 mod P = (n+1)^3 mod P P- Prime number Short example with the answer. Could you gives step-by-step solutions for my example. n^3 mod 61 = (n + 1)^3 mod 61 Integer…
0
votes
1 answer

Find minimum GCD of a pair of elements in an array

Given an array of elements, I have to find the MINIMUM GCD possible between any two pairs of the array in least time complexity. Example Input arr=[7,3,14,9,6] Constraint N= 10^ 5 Output 1 Explanation min gcd can be of pair(7,3) My naive…
0
votes
0 answers

Maximise the array sum modulo M under the given condition

Given an array=[a, b, c, ...]. You have to find the maximum value of [a * k1 + b * k2 + c * k3 + ...]%M. Where k1,k2,k3.. are any desired non-negative integers you can choose. M is known. Language- C++ Example Input arr=[7, 3,…
user10699596
0
votes
1 answer

How to find the number of solutions of modular equation?

Find the number of solutions of = x (mod m)
dandan
  • 163
  • 7
0
votes
0 answers

Which algorithm python use to calculate a^b%m using pow(a,b,m) so that it is so fast?

I want to calculate a^b%m where a,b and m are very large number like 2^256 or 2^512 bit. As far I know some method called bigmod or powmod which calculate a^b%m in O(log m) time complexity but as the number is huge we need to implement it using…
Tanmoy Datta
  • 1,604
  • 1
  • 17
  • 15
0
votes
1 answer

Algorithm for finding primitive roots from number theory

i would like to implement program for finding primitive number, for given prime number, for this one, i wrote following three program function primitive_roots=primitive_root(p) if ~isprime(p) error(' p must be prime number '); …
user466534
0
votes
0 answers

Comparing Negative Indices in Numpy with Postive Indices

I have a numpy array of indeterminate size and I need to compare some indices being used to extract data. For example if start_index > end_index I want an error to be thrown. However, sometimes the indices might be negative, most notably we might…
LukeC92
  • 121
  • 1
  • 11
0
votes
1 answer

Modular exponentiation overflows when using multiple of two uint_32 numbers

I am trying to implement RSA key signing and verifying. I am making use of the modular exponentiation where I am encountering errors possibly due to integer overflow. uint64_t modmult(uint64_t a,uint64_t b,uint64_t mod) { if (a == 0 || b <…
KAKAK
  • 879
  • 7
  • 16
  • 32