335 questions
4
votes
2
answers
110
views
How to reduce multivariate boolean expressions
I need to model a system of several boolean expressions in 512 variables. Due to the number of variables, I found the expressions are way too large to handle normally, which is why I need a way to ...
5
votes
2
answers
202
views
unsigned arithmetic - an indication that an overflow happened (ok! not happened but avoided by modular arithmetic)
I perform a subtraction with an unsigned type, say std::uint8_t. I can understand if the result will be obtained by modular arithmetic or not, by means of a comparison:
auto subtract (std::uint8_t x, ...
-1
votes
1
answer
79
views
Problem with Modular Subtraction while solving a CP question [closed]
I am trying to solve this https://codeforces.com/problemset/problem/2035/D codeforces problem. I understand the logic and implementation, but I guess I am failing a modular arithmetic. Here is my code:...
1
vote
3
answers
69
views
How to compute modular square roots in Pari/Gp when the modulus is composite?
pari is both a library and Computer algebra programming language through Pari/gp.
Now my problem is unlike most similar systems, pari/gp doesn’t decompose automatically modular square roots into prime ...
-1
votes
1
answer
131
views
Wrong output from custom big unsigned integer type when checking whether subtraction follow modular arithmetic
Here I am tasked with creating an UnsignedBigInteger class that can handle numbers bigger than a long. Am allowed to use a byte array as the internal representation, uint8_t[].
What I came up with is ...
6
votes
1
answer
176
views
Why is `2_u32..=u32::MAX` not covered when matching on `u64 % 2`?
If I try to build the following code:
fn main () {
let my_val: u32 = 42;
match my_val % 2 {
0 => println!("We're even now"),
1 => println!("Well, that'...
0
votes
0
answers
303
views
(Modulo Arithmetic) Modular congruence
I'm working through some challenges on cryptohack.org and am new to modular arithmetic. They describe it in the following terms:
Formally, "calculating time" is described by the theory of
...
0
votes
0
answers
84
views
COMPUTING a^b % 1e9+7
while computing the question a^b mod 1000000007 for large range of inputs. The major flaw is Integer Overflow after avoiding this we may get stuck by some modular operations So My code unable to ...
1
vote
0
answers
62
views
Replacing counter with a function
Let n be an odd number. Suppose we have the sequence s:=n,n+2,n+4,⋯. The goal is to associate this sequence with two other sequences, a and b. I will show how a and b are related to the original ...
3
votes
3
answers
566
views
How to perform integer modular exponentiation in Golang
How to calculate a**b % m where all the members are integers, and a^b is outside the int range?
I.e. to raise a to the power b under modulo m. I.e. an equivalent of this Python code:
pow(a, b, m)
0
votes
0
answers
173
views
How to do modular arithmetics on big numbers in Swift?
This comes up when evaluating a rolling hash of a string by subtracting the old weight of a character and adding a new weight for a new character.
Python has infinite length digits and is able to ...
0
votes
1
answer
109
views
How long will this modular exponentiaton need?
I have an algorithm for prime numbers, coded in python.
There I need to calculate exponentiations modulo large numbers.
To be more precise: For h and k let n = h* 2^k + 1 and I want to calculate 17^((...
3
votes
1
answer
782
views
Implementing Montgomery ladder methods for modular exponentiation in python
I'm trying to implement the mongomery-ladder method for modular exponentiation for RSA (so N=p•q, p,q are primes) in python, as followed in this paper:
My code looks like this:
x stands for base, k ...
4
votes
1
answer
375
views
How would I solve a linear Diophantine congruence in Python?
I was given a challenge where the solution involves solving a series of linear modular equations in 14 variables. The following is a selection of these equations:
3a + 3b + 3c + 3d + 3e + 3f + 3g + h +...
1
vote
1
answer
578
views
Modular Exponentiation Big O Notation
I'm taking an algorithms design and analysis class where we focus on the time and space complexity of common algorithms but I'm having a hard time understanding Big O notation/time complexity. For ...