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

Finding a mod m where a mod 2^i are known

I need to find the value of a mod m. But I dont have the value of a directly. I have the following modulus values of a. a mod 21 a mod 22 a mod 23 ... a mod 2n Now I need to find a mod m where m < 2n Can this be done in O(n) time ?
0
votes
2 answers

Combining ECDSA keys

How can I combine two ECDSA private/public keypairs into one? I know it's done with modular addition in openssl, I just don't understand how that works. Can anyone explain that to me?
Kontakt
  • 111
  • 1
  • 12
0
votes
1 answer

Finding the modified factorial N modulo some number coprime to N

Given two numbers N and p, let k be the maximum power of p such that p^k divides N! and let d = N!/(p^k). So d and p are coprimes. How do I find d mod p? Direct iterations will be impractical as N! will be very high when N is high. A more efficient…
Shashwat Kumar
  • 5,159
  • 2
  • 30
  • 66
-1
votes
1 answer

Find a multiplier which multiplies given indices into a formation of bits

I have a set of indices and a set of bit masks (the size of the sets is the same, and between 6-4096 but much closer to the lower bound). I also have a single bit mask which I will call the superset. I need to find a factor, that if for any index I…
user16009754
-1
votes
1 answer

My code is caught in an infinite loop when I'm trying to find the maximum non dividable subset using the naive approach

I'm aware of the modular arithmetic approach to solve this question, I just took it upon myself to solve it in the more naive way, but I just created an infinite loop somewhere in the inner for loop and there is no way out (Please do not tell me to…
-1
votes
1 answer

Modular Math - Easy approach (Fermat's ?)

I Know How to solve 5^31 mod 133 using Modular exponentiation, but I am wondering if there is a quicker way to solve this problem - like Fermat's Little theorem I won't have access to a calculator in the exam. So, I want to solve this quickly and…
-1
votes
1 answer

How to fix the difference in precision between double data type and uint64

I'm in the process of implementing Three Fish block cipher using MATLAB. At first, I implemented the algorithm on uint8 numbers to validate my code. Every thing was OK and the decryption was successful. But when I replaced the numbers to uint64 the…
Naseem
  • 39
  • 6
-1
votes
1 answer

How c calculates remainder?

I have strange behaviour in one of my functions. Code of program is very huge and hardly readable. So i attaches part of functions. If j lower than 4, it returns not actual remainder, but difference between j and 4. I tested and found, that 3 % 4 ==…
Vladimir
  • 294
  • 1
  • 3
  • 10
-1
votes
1 answer

How to return a String that has 'Excel style' column headings using Java?

I've been trying to figure out how to return a String formatted in such a way that it looks like this (for example): A(0) B(1) C(2) -> Z(25) -> AC(28) -> (to maxColumn()). 0 - - 1.2 - - 1 1.0 - - 8.8 6.1 3 -…
-1
votes
1 answer

Why don't we need to perform modulo operation on every operands in Fast Power algorithm?

Today I practiced with a puzzle "fast power", which used a formula: (a * b) % p = (a % p * b % p) % p to calculate (a^n)%p, something like that: 2^31 % 3 = 2 However, I am so confused when I found the answer used ((temp * temp) % b * a) % b; to…
彭浩翔
  • 83
  • 2
  • 9
-1
votes
2 answers

What is an efficient method for adding thousands of numbers quickly?

I am attempting to solve a challenge, but I have hit a roadblock. I am a beginner programmer attempting to add tens of thousands of numbers. If I wait long enough, my program can easily yield the correct sum, however, I am looking for a more…
jzbakos
  • 285
  • 1
  • 3
  • 12
-1
votes
1 answer

How to calculate timespans using modular arithmetic?

This question is basically about representing modular arithmetic concept in code and using the modulo sign. So recently I did a popup for SCCM installation, which should give user time to install an app, the client requuirements were to show the…
Robert Mazurowski
  • 327
  • 1
  • 3
  • 17
-1
votes
1 answer

PowerMod function working for small integers bur not for large ones

Here is the PowerMod function I implemented using ttmath BigInt library: #include #include using namespace std; template Integer iPowerMod(Integer & n,Integer & p,Integer & b) { if (n>b)…
-1
votes
2 answers

Count a Numeric Varchar Column Stored in Base Six

I have a table that stores a numeric value in a VARCHAR column, this column is storing values calculated in base six math. Meaning: 3.5 = 3 + 5 / 6 9.4 = 3.4 + 5.6 I need to get the sum of the values in these rows. I know I need to separate them…
user5697101
  • 571
  • 4
  • 12
-1
votes
1 answer

Random data in prime generation

In key generation process GnuPG displays: We need to generate a lot of random bytes. It is a good idea to perform some other action (type on the keyboard, move the mouse, utilize the disks) during the prime generation; this gives the random…