Questions tagged [modulus]

The remainder of the quotient of two numbers (usually integers).

847 questions
5
votes
7 answers

How to sort an array of odd numbers in ascending order, but keep even numbers at their position?

I want to sort only odd numbers without moving even numbers. For example, when I write : sortArray([5, 3, 2, 8, 1, 4]) The expected result is : [1, 3, 2, 8, 5, 4] I am new to JavaScript and I came across a challenge on the Internet that has me…
user7400006
  • 117
  • 1
  • 3
  • 9
5
votes
4 answers

Modular Exponentiation in Java

I need a way to calculate: (g^u * y^v) mod p in Java. I've found this algorithm for calculating (g^u) mod p: int modulo(int a,int b,int c) { long x=1 long y=a; while(b > 0){ if(b%2 == 1){ x=(x*y)%c; } …
Carl Hagen
  • 53
  • 1
  • 1
  • 5
5
votes
2 answers

What kind of data are exponent and modulus in c# RSACryptoServiceProvider?

I have the public key generated in c# with RSACryptoServiceProvider: 4kKhD/FWAMtQTRifArfXjxZN+6bOXTkHrVpyz/1wODhSOBqDewoSOFAp5boBd3wFjXszHA+gpUxZNWHRTj898Q== AQAB …
5
votes
1 answer

Why does int.MinValue % -1 cause and OverflowException

In 7.8.3. of the C# Specification regarding the Remainder operator it states the following: If the left operand is the smallest int or long value and the right operand is -1, a System.OverflowException is thrown. Therefore int.MinValue % -1…
Dirk Strauss
  • 630
  • 1
  • 8
  • 19
5
votes
1 answer

How to take modulus of a large value stored in array?

Suppose I have a integer array containing digits and I want to take modulus of value stored in it, i.e int a[36]={1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9} and convert it into a number like…
Vasu Dev Garg
  • 121
  • 1
  • 15
5
votes
2 answers

Why is Matlab Mod different from Wolfram Alpha

688^79 mod 3337 = 1570. When I tried this at wolfram alpha I got: but When I entered the same thing in Matlab, I get 364 as the answer. I got to be doing something wrong. Any light on this will be appreciated.
Juan Zamora
  • 386
  • 4
  • 11
5
votes
3 answers

The mod of negative numbers in C

In C the following code ... #include #include #include #include int main() { int result = (-12) % (10); printf("-12 mod 10 = %d\n",result); return 0; } gives this output > gcc modTest.c >…
SA610
  • 55
  • 1
  • 6
5
votes
1 answer

How to calculate with a number this big?

I am learning Pascal on my own for a month now and I came up to one problem I can't seem to solve. Basically I have 2 numbers, N and M, where N is less than 10100 000 and M is less than 108 and both are greater than 0. I need to calculate N mod M.…
Luka
  • 187
  • 3
  • 9
5
votes
2 answers

Moving modulus operator to the other side of the equation

I have a mathematical problem that is part of my programming problem I have a statement like a = b%30; How can I calculate b in terms of a? I gave it a thought but couldn't figure it out.
Old Person
  • 99
  • 1
  • 3
  • 6
5
votes
1 answer

Calculating modulus for large numbers in PL/SQL

I'm trying to calculate big modulus in PL/SQL. I implemented a method that I found on this location: http://en.wikipedia.org/wiki/International_Bank_Account_Number under Modulo operation on IBAN. But I get wrong results when I use this number:…
Bart
  • 97
  • 5
5
votes
1 answer

Why does 15.5 mod 5 = 0?

I understand 15 mod 5 = 0 because there is no remainder from the division. But why does 15.5 mod 5 == 0 also? Isn't there .5 remaining? $time = "15.5"; $interval = 5.0; if($time % $interval == 0) echo "it's time!"; else echo "not…
dukevin
  • 22,384
  • 36
  • 82
  • 111
5
votes
1 answer

modulus operator to run 1st and then every 3rd item

So i need it to run on the first loop and then every 3rd loop if ($k % 3 || $k==1 ) { echo '
'; } Seems simple to me, but i don't have the understanding of modulus
Jamie Hutber
  • 26,790
  • 46
  • 179
  • 291
4
votes
2 answers

Sorting with a modulus

I am trying trying to sort a list into columns with uksort. The array already alpha sorted, so it is like array('A','B','C','D','E','F','G','H','I','J','K','L','M') Which gets displayed in html, as floated elements: A B C D E F G H I J K L M I…
4
votes
2 answers

XSLT mod check for large numbers

I'm trying to do a modulus 11 check in XSLT 1.0 for a 17 digit number. However, it always seems to give the wrong output. The only information I've been able to find about this, was in this post, however, no solution was found. I have in the past…
m4rc
  • 2,932
  • 2
  • 22
  • 29
4
votes
2 answers

Xpath Cast node to number for mod

I have nodes that contain numbers that I would like to cast to a number and use mod. For example: 1 2 3 I've tried: num mod 3 -- returns NaN number(num) mod 3…
mbuff24
  • 425
  • 4
  • 14