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
2 answers

Computing $a ^ {^nC_r}$ % prime

I have uploaded my problem as screenshot.
Maggi Iggam
  • 682
  • 1
  • 8
  • 20
0
votes
2 answers

C++ code is giving a run-time error in the condition of for loop Whereas it is compiling correctly if it is replaced by code which makes same sense

#include using namespace std; int main() { vector luck; int k = 10; int sum = 0; for(int i = 0; i<5; i++) luck.push_back(i); for(int i = 0; i
0
votes
2 answers

How to find the inversion of f(x)=(6x mod 13)?

Finding the inversion of an easier function is simple. The way I find the way of doing this by flipping the x and the y in the equation and solving for y. But I am stuck on a certain part. y = (6*x) mod 13 x = (6*y) mod 13
0
votes
1 answer

Is there any relationship between remainder obtained through modulo 2 binary division and remainder obtained in a normal decimal division?

For some cases, modulo 2 binary division is giving the same remainder as a base 10 modulus but for some cases it is not. Is there some relationship between the two remainders? Example:- 1.) q = 101000110100000 p = 110101 modulo 2 binary division…
Krash
  • 2,085
  • 3
  • 13
  • 36
0
votes
1 answer

Number theory modular arithmetic how to account for adjustments

I am not sure whether my solution is justifiable (ans. 171) - Project Euler Q.19 since I am having a hard time getting my head around modular arithmetic and not really sure whether my approach to it was correct or not... I was having trouble on…
0
votes
1 answer

Python Modulo arithmetic (remainder) of a fraction

For the given problem, Modular Fractions: the result is: 2 because and when x is 2 we have (4%3=1) Question: is there a method in python that does this with fractions? I have tried Fraction(1,2) % 3 but the result is > Fraction(1,2)
adhg
  • 10,437
  • 12
  • 58
  • 94
0
votes
0 answers

Why is any number modulo a negative number negative in Python?

What is the justification for the result of x % a being negative whenever a is negative, in Python 3? In mathematics, modulo is not typically considered an operator, but rather a modifier on the equality relation, so the justification can't really…
Noldorin
  • 144,213
  • 56
  • 264
  • 302
0
votes
2 answers

Reliable multiplication and modulo with numbers larger than maxint

Situation After working on a coding kata I finally got the algorithm to work on my small test cases. Only to find out it did not work on a large scale, the time is not an issue but the size of the numbers are. In one of my calculations in one of the…
Rick Hoving
  • 3,585
  • 3
  • 29
  • 49
0
votes
0 answers

Do not understand the time complexity with respect to the input size of this modular exponentiation algorithm

Here is the pseudo code below: pow2(a,b,k) d := a, e := b, s := 1 until e = 0 if e is odd s:=s·d modk d:=d2 modk e := ⌊e/2⌋ return s end The number of time the loop runs is: log b(base 2), As this is the number of times b = e can be halved…
0
votes
1 answer

complexity of using Extended Euclid for multivariate gcd computations

part of exercise 31.2-7 of CLRS states show how to find integers x0, x1...xn such that gcd(a0, a1...an) = a0x0 + a1x1..an xn. Show that the number of divisions performed by your algorithm is O(n + lg(max{a0, a1...an}) I cannot figure out where…
0
votes
1 answer

Modular arithmatic in Rabin-karp algorithm

I am studying Rabin-karp algotithm for string matching from CLRS in which modular arithmetic is used for hashing which i haven't studied so what I don't understand is that how does (7 – 3·3)·10 + 2 (mod 13) evaluate to 8 (mod 13)
0
votes
2 answers

Finding the smallest number of elements that sum to a value (Python)

I have a set of positive integers values = [15, 23, 6, 14, 16, 24, 7] which can be chosen with replacement to sum to a number between 0 and 24 (inclusive), where the fewer values used, the better. For example, 16 + 16 (mod 25) = 32 (mod 25) = 7 but…
user8705712
0
votes
1 answer

Analysis of Linear congruential generator is wrong?

So in an attempt to better understand MSVC++'s implementation of rand, I re-implemented it and attempted to better understand it (and LCGs in general I guess). My implementation (which matches MSVC++'s almost exactly) is as follows: // vc++ impl. of…
Matthew
  • 268
  • 1
  • 11
0
votes
0 answers

Math behind sorting grade percentages for grade forecast

Title looks weird but I'll try to elaborate as much as I can. I want to write a program which is able to provide me the percentages I need to get all possible grades in the class (A,B,C; A = max 10 points lost, B = max 20 points lost, C = max 30…
0
votes
1 answer

Project Euler+ #97 modular exponentation not working

I am trying to solve Project Euler+ #97 from Hackerrank. The problem asks to calculate the last 12 digits of A x B ** C + D. My attempt was to use the modular exponentiation mod 10 ** 12 from Wikipedia in order to efficiently calculate the last 12…
Neil A.
  • 841
  • 7
  • 23