Questions tagged [modulus]

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

847 questions
-3
votes
2 answers

Convert one modulus value to other

Given N = A%B, how to find the value of A%C , where B > C. You are given value of N and C, but not of A. Is there any way to find this?
chao
  • 9
  • 6
-3
votes
2 answers

C : Modulus operator on unsigned int gives unexpected output

#include main() { unsigned a = -20; unsigned b = 10; printf("%d\n", (a % b)); printf("%d\n", (-20 % 10)); } Output: 6 0 The second printf prints the expected value of 0 while the first printf prints 6. Why this…
Nikunj Banka
  • 11,117
  • 16
  • 74
  • 112
-3
votes
5 answers

How to account for non-prime numbers 0 and 1 in java?

I'm not sure if this is the right place to be asking this, but I've been searching for a solution for this on my own for quite some time, so hopefully I've come to the right place. When calculating prime numbers, the starting number that each…
shady
  • 73
  • 1
  • 4
-4
votes
2 answers

Issue when using modulus operator or other arithmetic operands in a class

Hello im having an issue when using the % operator in my class method functions.The console window pop ups but then another window opens when saying " ".exe has encountered a problem and needs to close. any idea? Heres the line of code of when i…
user954004
  • 101
  • 1
  • 6
-4
votes
1 answer

nCr mod 10^9 + 7 for n<=10^9 and r <=1000

This may have been asked before but none of the answers I saw worked for me. I tried Lucas Theorem,Fermat's theorem but none of them worked. Is there an efficient way to find the value of: nCr mod 10^9+7 where n<=10^9 and r<=1000 Any help will be…
Klasen
  • 159
  • 1
  • 7
-4
votes
1 answer

Need math formula for free nights

UPDATE: Apparently, people think this is a homework assignment and are down voting my question. It's not. It's a re-life business logic question which is pretty complicated math as you can see from the answer. I would appreciate a little positive…
Thom
  • 263
  • 2
  • 13
-4
votes
1 answer

Nested loops and modulus c++

I am learning C++ and I have a problem with my program. It should print out following if n=11: *---------* -*-------*- --*-----*-- ---*---*--- ----*-*---- -----*----- ----*-*---- ---*---*--- --*-----*-- -*-------*- *---------* This is my code,…
-4
votes
3 answers

How does Bash modulus/remainder work?

Can somebody explain how it works? I just don't understand it. Why we get 2 from expr 5 % 3 or 1 from expr 5 % 4
Josh
  • 31
  • 2
  • 8
-4
votes
2 answers

PHP Calculation - Modulus 10 check digit generation

I got a problem here figuring out how to do this: I got a document no for example 5843 Starting with the right-most digit, multiply every other digit by 2 and 1 (For example, (3x2)+(4x1)+(8x2)+(5x1) and so on) For every multiplication that results…
Redzwan Latif
  • 886
  • 3
  • 14
  • 38
-4
votes
2 answers

Why is modulus with unsigned int runs faster than with unsigned long long?

Why to test speed of modulus? I have an app where modulus operation is performed millions times a second. I have to work with very big numbers, so I chose unsigned long long as a data type. About a week ago I've written a new algorithm for my app…
ForceBru
  • 43,482
  • 10
  • 63
  • 98
-4
votes
1 answer

Mod operator in Java

public class Triangle { public static void main(String[] args) { int n=12345, x=15; int res =(n % x); System.out.println(res); } } The statement int res = (n%x) is 0. Why?
-4
votes
3 answers

Modulus in language C

I'm having some trouble with this line of code: (sorry it is in danish) case 1 : system("cls"); printf("K maa kun have en veardi mellem 1 og 20\nIndtast k:"); scanf("%d", &k1); while(!(k1>=1 && k1 <=20))//Starten på…
Lasse
  • 597
  • 2
  • 10
  • 33
-5
votes
2 answers

How to find the result of (2^n)%p?

I was stuck in a question which asked to find (2^n)%p where n is a very large number of the order 10^36 and p is a prime.How to do this quickly???Here ^ means power I came across this algorithm but it gives stack overflow as 10^36 is very…
codeKNIGHT
  • 63
  • 1
  • 8
-5
votes
1 answer

Wrong modulus result when using unsigned int

I'll consider the following snippet : int a =-9; int m = 10; unsigned int m1 =10; std::cout<
-6
votes
1 answer

How to check if an input is a multiple of a number?

I have an if/else statement in my program, and the if statement checks 3 factors, one being if the input given from the user is a multiple of 5, and if it is not, it runs the program. I am currently using the modulus operator, but even when I input…
snaigy
  • 1
  • 2
1 2 3
56
57