modular-arithmetic Questions
1
Solved
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's odd"),
}
}
...
Berl asked 11/9 at 9:11
4
Solved
I want to compute nCk mod m with following constraints:
n<=10^18
k<=10^5
m=10^9+7
I have read this article:
Calculating Binomial Coefficient (nCk) for large n & k
But here value of ...
Carlotacarlotta asked 5/2, 2016 at 14:39
3
I know that,
(a*b)%m = ((a%m)*(b%m))%m
But there is a possibility of overflow.
For simplicity lets assume size of integer is 2 bits.
If a = 2 (i.e. 102) and b = 2 (i.e. 102), m = 3 (i.e. 112), t...
Designedly asked 1/2, 2015 at 5:35
2
Modular inverses can be computed as follows (from Rosetta Code):
#include <stdio.h>
int mul_inv(int a, int b)
{
int b0 = b, t, q;
int x0 = 0, x1 = 1;
if (b == 1) return 1;
while (a >...
Ebonee asked 30/11, 2018 at 15:22
4
Solved
I'm trying to implement a fast primality test for Rust's u32 and u64 datatypes. As part of it, I need to compute (n*n)%d where n and d are u32 (or u64, respectively).
While the result can easily f...
Grand asked 28/8, 2017 at 11:39
2
Solved
I have found that manually calculating the % operator on __int128 is significantly faster than the built-in compiler operator. I will show you how to calculate modulo 9, but the method can be used ...
Cathexis asked 30/12, 2020 at 11:51
14
Solved
I want to calculate ab mod n for use in RSA decryption. My code (below) returns incorrect answers. What is wrong with it?
unsigned long int decrypt2(int a,int b,int n)
{
unsigned long int res = 1...
Phellem asked 13/12, 2011 at 21:8
5
Solved
Recently I came to know that the mod('%') operator is very slow. So I made a function which will work just like a%b. But is it faster than the mod operator?
Here's my function
int mod(int a, int ...
Resnatron asked 25/10, 2015 at 18:27
1
I am currenty converting the nacl library to risc-v. I already have poly1305 working. I am trying to do this using the risc-v core instruction set, so I don't have a multiplier. The algorithm for P...
Emmer asked 1/11, 2019 at 14:4
2
Solved
I am trying to take ed = 1 mod((p-1)(q-1)) and solve for d, just like the RSA algorithm.
e = 5, (p-1)*(q-1) = 249996
I've tried a lot of code in javascript such as:
function modInverse(){
var e ...
Chrysoberyl asked 18/11, 2014 at 2:52
3
Solved
I'm trying to write a function that answers the question: if you start counting at a and stop counting at b, is c in that range (aka is c between a and b).
Normally a < c && c < b wo...
Selfexecuting asked 6/8, 2015 at 18:1
2
This is for an assignment I'm doing through school. I am having trouble generating a private key. My main problem is understanding the relation of my equations to each other. To set everything up, ...
Janettjanetta asked 22/9, 2013 at 4:6
5
Solved
Javascript evaluates the following code snippet to -1.
-5 % 4
I understand that the remainder theorem states a = bq + r such that 0 ≤ r < b.
Given the definition above should the answer n...
Zeringue asked 8/9, 2014 at 14:35
3
Solved
I saw a lot of competitive programmers writing code with ((a + b) % d + d) % d in C++. Why don't they just use (a + b) % d? What is that + d inside parentheses good for? Does it have something to d...
Karilla asked 12/7, 2017 at 13:58
1
Solved
In Rust, I have need of a numeric type with the property of having a domain symmetric around 0. If a number n is a valid value, then the number -n must also be valid. How would I ensure type-safety...
Forgiven asked 8/1, 2017 at 6:32
1
Solved
For my project, I need to solve for a matrix X given matrices Y and K. (XY=K) The elements of each matrix must be integers modulo a random 256-bit prime. My first attempt at solving this problem us...
Raspings asked 2/7, 2015 at 16:40
1
Solved
I want to solve linear and quadratic modular equations in Haskell in one variable. The way I am doing it right now is by putting x = [1..] in the equation one by one and finding the remainder (expr...
Renny asked 26/10, 2015 at 10:0
4
Solved
This is the code I'm using for calculating (n^p)%mod. Unfortunately, it fails for large values of mod (in my case mod = 10000000000ULL) when I call it from main() method. Any idea; why?
ull powMod...
Allseed asked 22/10, 2015 at 5:33
2
Solved
Extremely fast method for modular exponentiation with modulus and exponent of several million digits
As a hobby project I'm taking a crack at finding really large prime numbers. The primality tests for this contain modular exponentiation calculations, i.e. a^e mod n. Let's call this the modpow ope...
Gibby asked 11/7, 2014 at 10:52
2
Solved
Church numbers are an encoding of natural numbers as functions.
(\ f x → (f x)) -- church number 1
(\ f x → (f (f (f x)))) -- church number 3
(\ f x → (f (f (f (f x))))) -- church number 4
Neatl...
Ethnology asked 29/7, 2015 at 17:47
2
Solved
I am trying to implement a random-number generator with Mersenne prime (231-1) as the modulus. The following working code was based on several related posts:
How do I extract specific 'n'...
Faunie asked 24/6, 2015 at 21:10
1
In my project, one part of problem is there. But to simplify, here the problem is being formulated. There are two positive co-prime integers: a and b, where a < b. Multiples of a from 1 through ...
Underpinnings asked 11/9, 2014 at 5:20
8
Solved
I saw the following interview question on some online forum. What is a good solution for this?
Get the last 1000 digits of 5^1234566789893943
Tetryl asked 18/7, 2014 at 3:28
1
I wanted to use NTT for fast squaring (see Fast bignum square computation), but the result is slow even for really big numbers .. more than 12000 bits.
So my question is:
Is there a way to optim...
Chartreuse asked 2/9, 2013 at 16:1
8
Solved
I am working on a problem:
The user enters 3 tree heights and also the tree height limit. The program then calculates the amount of tree to remove.
Sample input:
Tree1: 14
Tree2: 7
Tr...
Fresno asked 16/9, 2013 at 20:14
1 Next >
© 2022 - 2024 — McMap. All rights reserved.