Questions tagged [mod]

For questions related with the *mod operation*, that can arise in Cryptography, Number Theory, Hashing, etc..

In computing, the modulo operation finds the remainder after division of one number by another (sometimes called modulus). Given two positive numbers, a (the dividend) and n (the divisor), a modulo n (abbreviated as a mod n) is the remainder of the Euclidean division of a by n.

437 questions
5
votes
2 answers

Modulus(%) operator in Typescript not working correctly for big numbers

I'm writing a specific validator and needed the modulus of a 16 digit number. Noticed that the operator % doesn't work correctly after 15 digits. I can rewrite my code to check less digits, but I could not find this limitation anywhere in the…
Danilo Petković
  • 51
  • 1
  • 1
  • 5
5
votes
3 answers

Can't explain php modulo result

Can someone please explain what is going on here? -1 % 7 = 6 https://www.wolframalpha.com/input/?i=-1%257 ...but echo (-1 % 7)."\n"; // prints -1 WRONG echo fmod(-1,7)."\n"; // prints -1 WRONG I also tried these examples from php.net, all of…
KPK
  • 442
  • 1
  • 5
  • 15
5
votes
2 answers

How do people develop WhatsApp mods like GBWhatsapp, etc (with extra features) when the source code of WhatsApp is not available?

Many third party whatsapp mods are developed with so many cool features like automatic replies, notifications when a person of interest comes online, message timer, etc. When whatsapp hasn't released any source code and with reverse engineering…
Vaibhav S
  • 115
  • 1
  • 12
5
votes
1 answer

Numeric addition in c++

I was trying to solve the following problem: https://leetcode.com/problems/add-digits/ The following method took 12ms to complete all tests: int addDigits(int num) { return 1+((num-1)%9); } whereas the following took only 8ms: int…
4
votes
3 answers

Divide two integers without using multiplication, division and mod operator in java

I write down a code which find out quotient after dividing two number but without using multiplication,division or mod operator. My code public int divide(int dividend, int divisor) { int diff=0,count=0; int fun_dividend=dividend; int…
Encipher
  • 1,370
  • 1
  • 14
  • 31
4
votes
1 answer

Set bits combined with exponential modular arithmetics

I got this question yesterday in a challenge. I thought I had coded it correctly and my sample test case was passed. However not even a single test case passed at the backend. Here is my code. Please, someone, help me out. The challenge is over for…
Brij Raj Kishore
  • 1,595
  • 1
  • 11
  • 24
4
votes
3 answers

signed int modulo unsigned int produces nonsense results

I need to perform a real mathematical modulo in C. It makes sense for me to allow negative numbers for the moduled argument, since my modular calculations can produce negative intermediate results, which must be put back into the least residue…
Youda008
  • 1,788
  • 1
  • 17
  • 35
4
votes
4 answers

VBA Odd Numbers/Mod

I'm looking for some help with my VBA script. I'm stuck on trying to figure out how to use the mod function. This is what I've done so far: Function AddOddNumbersWithMod(nr) Dim i, sum sum = 0 For i = (IF 1 MOD 2 = 0) to nr step 1 …
K. L.
  • 71
  • 2
  • 4
4
votes
3 answers

A sign preserving modular distance

I am looking for a modulus operator Mod(a,b,m) such that: Mod(2,6,7)=-3 Mod(6,2,7)=3 That is, the operator avoids the 4-hop path between 2 and 6 and, instead, circles around via a path of length 3. The answer preserves the path direction if you…
Richard
  • 56,349
  • 34
  • 180
  • 251
3
votes
1 answer

2^65 modulo 101 incorrect anwser

This code checks that the value a maps uniquely for the values 1 to 100 using the formula (a^x) % 101 local function f(a) found = {} bijective = true for x = 1, 100 do value = (a^x) % 101 if found[value] then …
Nifim
  • 4,758
  • 2
  • 12
  • 31
3
votes
2 answers

java.lang.NoClassDefFoundError: jdk/nashorn/api/scripting/NashornScriptEngineFactory

I want to code a Minecraft mod in 1.16.3. I have already make a mod in 1.12.2 but I didn't have this problem. I just download the 1.16.3 forge Mdk and build it for eclipse (with 'gradlew eclipse' in cmd) but when I try to run the mod (with…
Luzog78
  • 53
  • 1
  • 1
  • 5
3
votes
1 answer

How to patch methods using harmony

How do you replace a method with parameters at runtime using Harmony in c#?
jj5
  • 31
  • 1
  • 2
3
votes
3 answers

Why does the C++ modulo operator return 0 for -1 % str.size()?

I'm confused why the following code produces this output: #include #include using namespace std; int main() { int i = -1; string s = "abc"; int j = s.size(); int x = 1 % 3; int y = i % j; int z = i %…
3
votes
1 answer

Division with remainder with positive remainder

Let a, b be real numbers with b != 0. I want to perform division with remainder of a by b. The result should be the unique real number r contained in [0, |b|) such that a = bc + r for some (unique) integer c. std::fmod yields a similar result, but…
0xbadf00d
  • 17,405
  • 15
  • 67
  • 107
3
votes
2 answers

How to find the largest multiple of n that fits in a 32 bit integer

I am reading Functional Programming in Scala and am having trouble understanding a piece of code. I have checked the errata for the book and the passage in question does not have a misprint. (Actually, it does have a misprint, but the misprint does…
Allen Han
  • 1,163
  • 7
  • 16
1
2
3
29 30