Skip to main content
Filter by
Sorted by
Tagged with
-2 votes
0 answers
22 views

accumulator problem to know which set contain a element? [closed]

Problem statement. Given : Set1 = (a * b * c * d * ……) MOD N Set2 = (e * f * g * ….) MOD N c, g. We want to know from which set c and g belong, see we only have the above final value’s { set1, set2, N,...
user28766874's user avatar
3 votes
2 answers
106 views

Convert floating-point value to cyclic range?

I'm not sure if I'm using the right terminology, but occasionally I find myself needing to canonicalize a floating-point value to a range in a cyclic manner. (This can be useful, for instance, for ...
Boann's user avatar
  • 49.8k
-3 votes
0 answers
39 views

Python Modulo operator bug [duplicate]

I'm using Python version 3.9.12. I asked Python what the remainder of -7 divided by 3 is (-7%3), and it answered 2! It should be -1, right? Am I getting it wrong? What's going on?
kaveh yousefpouran's user avatar
-5 votes
0 answers
63 views

Understanding the precedence of the modulo operator [duplicate]

I'm using Zed Shaw's "Learn Python 3 The Hard Way"; the problem exercise is on page 16, and refers to counting eggs: print(3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6) The author says the answer is 6....
Beginners Please's user avatar
0 votes
0 answers
89 views

The fastest MOD algorithm in C++ for extremely large uint_64_t numbers stored in an array

I am working with extremely large numbers and would like to verify my Karatsuba multiplication result ((2^136279841)-1)^2 which needs (532 344 * _m256i_epi64)^2 i.e. 4,258,752 uint64_t to store the ...
Caster's user avatar
  • 11
3 votes
2 answers
193 views

C++ modulo returning inconsistent results

Can someone tell me why these two functions return different results? After running code #include <string> #include <stdio.h> #include <iostream> using namespace std; int returnN(...
aloysiustanrs's user avatar
1 vote
0 answers
62 views

How to evenly divide a total value into predefined values with buffers in Python?

I've been working on a fence calculation tool that breaks down a total length, as equally as possible, into components (rails and posts) using a predefined set of rail lengths. The user can choose a ...
Arnaud Hanssens's user avatar
0 votes
0 answers
47 views

Can anyone explain why this RSA calculation not working

I made a RSA encrypting and decrypting program. Everything works well as it is suppose to be. However when I decrypt the message, it doesn't give me the message. Can somebody check which part is wrong ...
user26695021's user avatar
0 votes
0 answers
45 views

Wrapping a number within a specific range

I have come across the below wrapping formula to wrap a number x within a range [min, max]. const wrappedValue = (x - min) % (max - min + 1) + min; I am trying to understand the formula. Specifically,...
meallhour's user avatar
  • 15.5k
1 vote
2 answers
89 views

Shifting a number based on the remainder of it divided by 4 - C

I have a function implemented which reverses the bits in a number. The number of bits in the number to be reversed can vary. However, of course it must be shifted to the left at the end to align with ...
Engineer999's user avatar
  • 3,925
2 votes
3 answers
128 views

How to divide the numbers between two number and see how many numbers there modulus = 0

I have a task that forbids me from using an array or String or loops only if conditions or switch cases. The task is that I need to take three numbers from the user and see the how many numbers ...
Youssef Trying's user avatar
0 votes
0 answers
30 views

Problems repeating Shekhar's calculations in his article on Asymmetric and Post Quantum Cryptography

This is a great article at https://medium.com/@shekhar.siva2609/asymmetric-encryption-and-post-quantum-cryptography-bea4a5a08ae5, particularly if you're interested in Elliptic curve cryptography. ...
Aydin Onac's user avatar
0 votes
0 answers
74 views

C++ - Questions about bit shift operators (<< and >>) [duplicate]

Consider the below code: std::string g_CharTable = "stjkloptrew23456mncv891TZUIOPAS"; std::uint32_t value = 123456789 std::string hash; for (std::size_t i = 0; i < 5; ++i) { ...
Jean-Milost Reymond's user avatar
0 votes
0 answers
29 views

How to pin modulus of the certificate public key on Android?

So I am using Android TrustKit to pin certificate's Subject Public Key Info. One of the security guys suggested I pin modulus of the public key, however, I cannot find any sort of examples on how to ...
mike.tihonchik's user avatar
0 votes
2 answers
69 views

How to convert a time string measured in 24 hours cycle to 12 hours cycle?

I have a stored value of an hour in a 24-hour format in a variable named hour. My task is to convert this value to a 12-hour format and print the result. I tried while-loops, if-elif-statements. I ...
Dante Taviantz's user avatar
0 votes
1 answer
41 views

Math power function with modulo arithmetic in Python

I am learning group homomorphism (a Math concept) with modulo arithmetic. Basically, I want to show that g^(2x+8y) mod n equals to (g^(2x) . g^(8y)) mod n. I have the following python code: g = 57 n = ...
Jimmy Chu's user avatar
  • 982
3 votes
2 answers
117 views

Why is `array % 1` running 150% slower for smaller numbers than larger ones?

I would understand if numpy was smart enough to see that array % 1 gives a constant result (for that dtype), and that its runtime was independent of the input. I would also understand if runtime was ...
bers's user avatar
  • 5,724
0 votes
0 answers
97 views

C# modulo operation with decimal yields inconclusive result

I have a very quick question, based on the following C# code: decimal _sampleCounter = 2100m; decimal wrong = _sampleCounter % (30m / 2.3m); decimal correct = 2100m % (30m / 2.3m); Console.WriteLine(...
Philipp's user avatar
  • 11
0 votes
2 answers
151 views

How to include a modulus operation in CasADi function

I can't find a modulus function in CasADi. I want to build a function with something like this: from casadi import MX angle = MX.sym('angle') wrapped_angle = ((angle + 180) % 360) - 180 TypeError: ...
Bill's user avatar
  • 11.5k
1 vote
2 answers
115 views

Modulus `%%` giving unexpected result for `3.1 %% 0.1`. Is this expected?

I'm using the base modulus (%%) operator, and just struggling to understand the following behaviour. My understanding is that %% returns the remainder after dividing 2 numbers. So eg: 5 %% 2 # [1] 1 ...
rosscova's user avatar
  • 5,580
2 votes
1 answer
103 views

Generate new Column in Dataframe with Modulo of other Column

I would like to create a new column "Day2" which takes the second digit of column named "Days", so if we have Days equal to 35, we would take the number 5 to be in "Day2",...
the phoenix's user avatar
1 vote
1 answer
121 views

Counting the number of distinct digits that divide a number- Unable to pass all test cases

I was practicing from Leetcode earlier and I came across this question: Given an integer num, return the number of distinct digits in num that divide num. An integer val divides nums if nums % val == ...
ShraavaniJha's user avatar
0 votes
0 answers
15 views

Raymarcher glitches when performing local transforms using modulus "coordinate-space" repeat trick

I am building a ray marcher in GLSL to further understand the language. I am attempting to repeat the coordinate space using modulus when calculating the SDF so that "infinite" spheres ...
canalesbr1's user avatar
0 votes
0 answers
26 views

why does the value of n increases by one in in first iteration while the result of (n+1)%26 is 0.26

in line 10, n = (n + 1) % 26; the value of n should be 0.26 in first iteration as it has not been rounded up or rounded down so why has the value of n increased by one ?? I don't understand this part ...
WiglyString's user avatar
0 votes
1 answer
58 views

modulus maths question - competitive programming

I was attempting past competition questions and was stuck on this question. The solution was made public, but I still can't seem to get how did they derive the solution logic. question: Meow is ...
Jia Yee Chong's user avatar
2 votes
3 answers
160 views

Homework Help - Using Modulo to Count out Bills and Coins

NOTE: I do NOT want the answer! I am hoping to get guidance on next steps I am new to python and have a question about a problem I'm working: Define a function consolidate_change that takes as ...
Gian-Luca Matsuda's user avatar
4 votes
3 answers
80 views

R - Addition after modulo operation

Running the snippet D=1;for (j in 1:5){D=(D-1)%%4;print(D)} I get the expected outcome: [1] 0 [1] 3 [1] 2 [1] 1 [1] 0 But when I add 1 to the result D=1;for (j in 1:5){D=((D-1)%%4)+1;print(D)}, it ...
Pradeep Chaghran's user avatar
0 votes
1 answer
38 views

Dispatch metadata from WordPress DB query into a table with 4 columns

I have a variable (array) and is returning the following: array(13) { ["meta_id"]=> string(1) "2" ["post_id"]=> string(4) "2112" ["...
Rene Zammit's user avatar
  • 1,151
3 votes
1 answer
190 views

Why don't x86-64 (or other architectures) implement division by 10?

I'm familiar with compilers replacing division and modulo by a constant (e.g. x/10) with multiplication by a magic number (x * 0xcccccccd) >> (32 + 3). Compiler example here. movl $...
Kaia's user avatar
  • 871
0 votes
0 answers
11 views

Best way to set desired range with inverse trig functions? [duplicate]

I am currently performing some inverse trigonometric operations. The actual formula I am using is at the bottom of this post, but is not super important. Minimally, I am taking an arctangent atan2(x,...
Him's user avatar
  • 5,531
6 votes
1 answer
197 views

Why two modular operations cannot be optimized as well as one modular operation

I'm reading a C++ function that handles timestamps, and there's an expression like this: t % (60 * 60) % 60 I thought this expression was strictly equivalent to: t % 60 However, when I entered this ...
2n8 asm's user avatar
  • 61
0 votes
0 answers
25 views

How to sort lists of matrices and find the index of a matrix on a list?

I am working with lists of 3x3 matrices with elements from the set {0,1} (modulo 2). Problem: As in the title I am trying to sort these lists so that I can see if another list that may contain the ...
TheDarkFade's user avatar
0 votes
1 answer
88 views

Google Sheets - Why are there garbage digits in MOD(??)&"*"? [duplicate]

tl;dr - why am I getting these weird remainders in MOD()&"*", which are not showing up in MOD()? On behalf of an old-timey cheesemonger acquaintance of mine, I'm trying to convert a ...
EvangeliusAg's user avatar
2 votes
2 answers
76 views

How to write c language modulo 2 with use mpfr function?

Here is the example of code in c language: int i; for (i=0; i < 100; i++) { if (i % 2 == 0) { // do something } } But i variable is standard integer. I need this code of modulo 2 with use mpfr_t ...
Sylwester Bogusiak's user avatar
-1 votes
2 answers
236 views

Python how to convert total teaspoons to tablespoons, ounces, cups, and pints using modulus and floor division

I need to take a given amount of teaspoons and convert it to statements in which the bigger units fill first and the smaller units fill second. For example, this is what it's supposed to look like: ...
reluctant programmer's user avatar
0 votes
2 answers
332 views

How to evaluate an expression in SageMath over Zmod?

I need to compute some automatically generated expressions, which may contain square roots, with the class Zmod. For example, I want to evaluate the following expression modulo 9 (thus, using the ...
G.F's user avatar
  • 157
1 vote
1 answer
75 views

Alternate show of every 3 then every 1 item

My current code is like this which alternates between showing every 2 then every 1 item inside loop. I want it to show every 3 then every 1 item. I use Adonis JS template engine (Edge) <div class=&...
Mehdi Azmoudeh's user avatar
1 vote
1 answer
50 views

swap group of characters every words in list

I have a list like : s=['eb736d0020000000073a...002300001f', '00bd860020000020efad...002300003f', '1452770020000040ef53...002300005f', 'fbeadb002000006006ac...002300007f', 'ec38b600200000801441......
Philippe Leray's user avatar
0 votes
2 answers
87 views

JS Last value in array is never checked when looped

I am trying to loop through an array to check whether none of the values when compared with all of the remaining values in the array return a 0 after using the modulo operation. In effect, this should ...
Drawleeh's user avatar
  • 259
0 votes
2 answers
57 views

Save data every t time units in R

I want to do move through a loop and save a value at particular time intervals. I was thinking of something with this form: t <- 0 t_end <- 10 time_step <- 0.01 ...
dchauri's user avatar
0 votes
1 answer
304 views

Julia modulo of vector (or remainer of vector)

How do I obtain the modulo of a vector in Julia. There are two ways in Julia to perform a modulo: mod(9,5) or equivalently: 9 % 5 However, neither works with a vector. This also the came for ...
Bastiaan Quast's user avatar
1 vote
1 answer
186 views

Can I generate x509 certificate with negative RSA key modulus?

So far I tried to generate x509 certificate in Go, using x509 library, but this doesn't succeed, since Go doesn't allow to generate negative modulus. I tried to use openssl: openssl req -nodes -new -...
armaka's user avatar
  • 264
1 vote
0 answers
20 views

Form automatic submit does not work well, because the form is sent several times

The goal I had set myself was to send the form automatically after X time had passed. The code I put down creates the send at regular intervals as if you had used the function: setInterval. I don't ...
RMO's user avatar
  • 11
0 votes
1 answer
238 views

How can I select every nth date in Snowflake?

Say I have a table in Snowflake with fields delivery_date, formatted as a DATETIME, and daily_volume formatted as an INT. Daily_volume follows a pattern that repeats every 10 days. How would I query ...
nwhaught's user avatar
  • 1,592
0 votes
1 answer
77 views

How do I use the modulus operator?

When using the % operator I am left with the error "Did you forget a , here?". Is there another keyword for % in ReScript? Js.log(20 % 2) Note: This is a translation of this question for ...
glennsl's user avatar
  • 29.1k
2 votes
1 answer
116 views

BigInt modulo float

I would like to calculate the a bigint modulo a number (float) As a % b will necessarily be lower than b, the result can be expressed as a number. example: with 10 000 000 000 000 000 004 modulo 1.43 ...
Yukulélé's user avatar
  • 16.9k
0 votes
3 answers
879 views

Is there a modulo operator for real variables in gnuplot?

So, gnuplot (I use 5.4 patchlevel 8) does not seem to support the modulo operator for real values: gnuplot> a = 5.0 % 2.0 non-integer operand for % Is there any workaround over this ...
coderodde's user avatar
  • 977
-4 votes
1 answer
58 views

Why does this print out 21 and not 11? [duplicate]

The code I wrote was meant to take the sum of the digits of an integer number, e.g. 143 gives out 8, 020341 give out 10. This is the code I wrote for it I intended for this to print out 11 but it ...
Jensen's user avatar
  • 1
0 votes
1 answer
76 views

How to properly use Modulo in Rabin Karp algorithm?

I am trying to solve leetcode problem 187. Repeated DNA Sequences using Rabin Karp algorithm with rolling hash approach. At first, I solved the problem without using any MOD operations like below. ...
Setu Kumar Basak's user avatar
-2 votes
1 answer
51 views

Array Question for simplilearn Full stack java Program

I am trying to implement ... When I run the application, it ... I had expected it to return ... for the input N = ... and AR = ... Here is the full code: static long calculate() { final ...
Shivam Pal's user avatar

1
2 3 4 5
41