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

Calculating W for NTT (Integer Fast Fourier Transform)

I'm attempting to implement an NTT (Number Theoretic Transform) in Objective C, however the abstract mathematical documents posted online are missing crucial details. I've found the following existing Question on Stack Overflow which purports to…
JasonA
  • 36
  • 2
0
votes
1 answer

Arithmetic exception with rand() and mod

Twice now my server has crashed after several days of running on this line. int randomValue = rand() % m_list.size(); where m_list is std::list m_list; The crash is Program terminated with signal 8, Arithmetic exception. getting the size of…
Josh Brittain
  • 2,162
  • 7
  • 31
  • 54
0
votes
1 answer

Modular Calculation 32-bit vs 64-bit OS

I lack the knowledge of how performance is affected by CPU specifications. I'm running an application to perform modular calculation (DH Key Exchange) on a Windows platform with the following parameters: Modular: a prime number = 4096…
0
votes
1 answer

Division with modulus remainders

How can you do division with modulus remainders? For example: Find the remainder when 9^2012 is divided by 11. Using modular arithmetic, 9 == 1(mod 4), so 9^2012 == 1^2012(mod 4). Therefore, 9^2012 == 1(mod 4). Also, 11 == 3(mod 4). To answer the…
Jason Chen
  • 312
  • 1
  • 4
  • 12
0
votes
2 answers

What function has these integer results?

For example, I have a reference number a = 15 and b= 3. If x=2, f(a,b,x) = 1 because if one divide 15 into 3 parts, the number 2 is in the first part. If x=7, f(a,b,x) = 2 because if one divide 15 into 3 parts, the number 7 is in the second…
David Sousa
  • 383
  • 2
  • 13
0
votes
1 answer

How to calculate nPr mod m, when m is a prime number?

I need to find out the value of nPr%m. This is the approach I used. Find, n!%m, (n-r)!%m and divide them However, for certain cases, (n-r)!%m is greater than n!%m, so the resultant nPr is 0. What do I need to do then?
user2441151
  • 1,522
  • 3
  • 17
  • 26
0
votes
1 answer

How to find multiplicative orders of all elements in F 13?

How to find multiplicative orders of all elements in F 13? I am working on some Finite fields and I was referring to some online class material. Is there any way to find this?
kingmakerking
  • 2,017
  • 2
  • 28
  • 44
0
votes
2 answers

Simplify modular exponentiation C++

I am attempting to write the decryption function for an RSA encryption system, everything seemed to be working fine for very small numbers, however sometimes the output just isn't correct (I think that the cause may be a floating point error or some…
Michael
  • 83
  • 1
  • 2
  • 8
0
votes
2 answers

Remainder When Dividing Large Number

What is the remainder when 30^74 is divided by 57? I know normally to solve such a problem, you would use Fermat's Little Theorem, but in this case, 57 is not a prime number, so I am unsure how to approach this. Any ideas?
user2266603
  • 103
  • 1
  • 3
  • 9
0
votes
3 answers

Modular arithmetic: Division over factorials % Prime

I want to efficiently calculate ((X+Y)!/(X!Y!))% P (P is like 10^9+7) This discussion gives some insights on distributing modulo over division. My concern is it's not necessary that a modular inverse always exists for a number. Basically, I am…
crazydiv
  • 812
  • 9
  • 30
0
votes
1 answer

What is the best way to store binary data in a number?

I am wondering if it is possible to store binary data in a number, and how the most binary data possible can be stored in a single number. For example, let's say I want to store the following text in a number: Lorem ipsum dolor sit amet,…
Razick
  • 744
  • 2
  • 9
  • 28
0
votes
1 answer

Gaussian elimination modulo p

I'm trying to rewrite a code in Java solving a set of linear equations doing Gaussian Elimination on floats, to work on equations modulo a prime. The problem is that it does not work, and I cannot figure out what's wrong. It seems to work on small…
Jambaman
  • 741
  • 9
  • 22
0
votes
1 answer

Curious behaviour of inverse modulo

I wrote the following code to calculate n!modulo p...Given that n and p are close...but its running in a rather funny way, cant figure out the bug..There is some overflow somewhere..The constraints are 1 < P <= 2*10^9 1 <= N <= 2*10^9 though it runs…
0
votes
2 answers

Calculate n where a^n mod m = 1?

What is fastest way to calculate the first n satisfying the equation a^n mod m = 1 Here a,n,m can be prime or composite mod : is the modulus operator
rohangulati
  • 251
  • 1
  • 4
  • 12
0
votes
0 answers

Large values in segment tree for product range queries

I wrote code for firing product range queries on an array. Note: This question not a duplicate to Multiplication in a range. My problem is something different I wrote the code for this, // Program to show segment tree operations like construction,…
user650521
  • 583
  • 1
  • 9
  • 23