modulo

Filtering odd numbers

M = [[1,2,3], [4,5,6], [7,8,9]] col2 = [row[1] + 1 for row in M if row[1] % 2 == 0] print (col2) Output: [3, 9] I'm expecting it to filter out the odd numbers, but it does the opposite. ...

How do I find the smallest positive integer congruent to i modulo m?

I have a variable that holds an angle, in degrees, which can be both positive and negative. I now need to make sure that this number is between 0 and 360 only. The number is a double. What would a nice algorithm for doing that be? Simply doing angle % 360 does not work, because negative numbers end up still being negative. Bonus points ...

How find a variable value in MOD expression?

9 = 2^X mod 11 What is X and how do you find X? Its related to finding the plain text in RSA algorithm and I'm writing a C program for it. ...

Ruby/Rails: get elements from array where indices are divisible by x

How could I implement this? I think my solution is very dirty, and I would like to do it better. I think there is an easy way to do this in Ruby, but I can't remember. I want to use it with Rails, so if Rails provides something similar that's ok, too. usage should be like this: fruits = ['banana', 'strawberry', 'kiwi', 'orange', 'grapef...

How can I get alternate styling in <ItemTemplate> (.NET)?

I'm using EPiServer for this website. Unlike asp:DataList, EPiServer:PAgeList does not have AlternatingItemTemplate. So I need to create a counter and increase this counter in my <ItemTemplate>, and then use modulus to return whuch css style to append to article / page. Modulus "code" - fromcode behind: return index % 2 == 0 ? "style...

What does the percent sign mean in PHP?

What exactly does this mean? $number = ( 3 - 2 + 7 ) % 7; ...

Fiege Fiat Shamir Question about quadratic residues

Hello people I am currently studying Fiege-Fiat Shamir and am stuck on quadratic residues. I understand the concept i think but im not sure how to calculate them for example how would i calculate v | x^2 = v mod 21 | x =? ___________________________________ 1 x^2 = 1 mod 21 1, 8, 13, 20 4 x^2 = 4 mod 21 2, 5, 16 7 ...

jquery slide show - why does this code work?

I was in the middle of coding a slideshow in javascript using jquery, when I ran into something that was doing what my several lines of code was doing in a couple lines. Problem is, I don't comprehend how it works so I can modify it. var imgs = [ 'image1.jpg', 'image2.jpg', 'image3.jpg']; var cnt = imgs....

How to calculate modulus of large numbers?

How to calculate modulus of 5^55 modulus 221 without much use of calculator. I guess there is some simple principles in number theory in cryptography to calculate such things. Thanks ...

Modular Exponentiation for high numbers in C++

Hello all! So I've been working recently on an implementation of the Miller-Rabin primality test. I am limiting it to a scope of all 32-bit numbers, because this is a just-for-fun project that I am doing to familiarize myself with c++, and I don't want to have to work with anything 64-bits for awhile. An added bonus is that the algori...

Difference Between Modulus Implementation in Python Vs Java

I've noticed differing implementations of the modulus operator in Python and Java. For example, in Python: >>> print -300 % 800 >>> 500 Whereas in Java: System.out.println(-300 % 800); -300 This caught me off guard, since I thought something as basic as modulus was universally interpreted the same way. I'm a fan of Python's interp...

Will using modulus favour high numbers?

Will adding 6 random unique numbers in the range 0-32 and doing a modulus on the result favour a high number? Example: 9 +10 +11 +18 +25 +28 +32 = 133 % 20 = 13 ...

Base Conversion Problem

I'm trying to convert an integer to a string right now, and I'm having a problem. I've gotten the code written and working for the most part, but it has a small flaw when carrying to the next place. It's hard to describe, so I'll give you an example. Using base 26 with a character set consisting of the lowercase alphabet: 0 = "a" 1 = "...

Modulus PHP Problem

I have a problem, I am trying to calculate what the lowest prime is of a number but I do not understand the result that PHP is giving me. If I have this number $number = 600851475143; Then I modulus it: $primes = array( 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97); foreach($p...

Returning Time Components with Modulus

Someone does 20 Hours 42 Minutes & 16 Seconds in one shift totaling 74536 seconds. How do I get the hours from number of seconds the person has done for that shift? 20 * 60 * 60 = 72000 42 * 60 = 2520 16 = 16 + ----- Total = 74536 ____________________________...

Modulo operator in Objective-C returns the wrong result

I'm a little freaked out by the results I'm getting when I do modulo arithmetic in Objective-C. -1 % 3 is coming out to be -1, which isn't the right answer: according to my understanding, it should be 2. -2 % 3 is coming out to -2, which also isn't right: it should be 1. Is there another method I should be using besides the % operator ...

How to find the remainder of large number division in C++?

Hello, I have a question regarding modulus in C++. What I was trying to do was divide a very large number, lets say for example, M % 2, where M = 54,302,495,302,423. However, when I go to compile it says that the number is to 'long' for int. Then when I switch it to a double it repeats the same error message. Is there a way I can do...

"Nearly divisible"

I want to check if a floating point value is "nearly" a multiple of 32. E.g. 64.1 is "nearly" divisible by 32, and so is 63.9. Right now I'm doing this: #define NEARLY_DIVISIBLE 0.1f float offset = fmodf( val, 32.0f ) ; if( offset < NEARLY_DIVISIBLE ) { // its near from above } // if it was 63.9, then the remainder would be large,...

Fastest way to calculate a 128-bit integer modulo a 64-bit integer

I have a 128-bit unsigned integer A and a 64-bit unsigned integer B. What's the fastest way to calculate A % B - that is the (64-bit) remainder from dividing A by B? I'm looking to do this in either C or assembly language, but I need to target the 32-bit x86 platform. This unfortunately means that I cannot take advantage of compiler sup...

How do I do modulus in C++?

How do I perform a mod operation between two integers in C++? ...