I’m only confused because I think a study blog did this incorrectly… they said the answer was 50
how many multiples of 18 are there between 100 and 1,000?
but because it is not inclusive, would it not be 49… as 101/18 = 5.6… and 999/18 - 55.5 and 55.5-5.6 = 49 (rounded down)
Doing 55.5 - 5.6 = 49.9 seems really fishy and can lead to off-by-1 errors easily.
The smallest multiple is 186 = 108 and the largest is 1855 = 990, so you want to count the number of numbers in {186, 187, 188, …, 1855} (which is not 49!). I know there are other ways, but I like to do the following:
|{186, 187, 188, …, 1855}| = |{6, 7, 8, …, 55}| = |{1, 2, 3, …, 50}|
So there are 50 elements.
Another way to look at this question (pretty close to what @avneety did) is to divide all the integers in the [101, 999] interval by 18 and count the number of integers among the results. (Of course, it’s enough to divide just the margins.)
Between 5.6 and 55.5 there are 55-6+1=50 integers.
Basically, the number of n multiples between x and y is :
[(Y-X)÷n] +1. You should either round up or round down and add one. 990-108 = 882. 882/18 = 49 . 49+1= 50.
The reasoning behind the +1 is clear. Just try counting the numbers between [1,2].
You probably meant “the number of multiples of n between x and y”.
Your formula yields the same answer to these two intervals of equal length: [18,36] and [19,37]; that is not correct.
@gcf101 yes, thank you. I have been schooled in another language, and I am not completely at ease with the terminology. However, Can you explain the difference between N multiples and multiples of N?
EDIT : Sorry, I misread your post. I will explain myself in a minute.
@Soheils you should also define what “between x and y” means (is it strictly between x and y, as in the interval (x,y)? or the closed interval [x,y]?).
Assuming you meant [x,y], where x and y are integers and x ≤ y, the smallest multiple of n contained in [x,y] is n⌈x/n⌉ and the largest multiple of n is n⌊y/n⌋. Then the number of multiples of n in the closed interval [x,y] is ⌊y/n⌋ - ⌈x/n⌉ + 1. Not sure if there is an easier way of writing that expression. Usually I just count them as I did above.
@gcf101’s example:
When x = 18, y = 36, n = 18, then ⌊y/n⌋ - ⌈x/n⌉ + 1 = ⌊36/18⌋ - ⌈18/18⌉ + 1 = 2 - 1 + 1 = 2.
When x = 19, y = 37, n = 18, then ⌊y/n⌋ - ⌈x/n⌉ + 1 = ⌊37/18⌋ - ⌈19/18⌉ + 1 = 2 - 2 + 1 = 1, as expected.
@MITer94 Thank you for your complete explanation. How did you use the round down sign (I.E floor function)?
And your assumption was correct, I meant closed interval. I should have made that clear, but at least I used the correct domain in my example. Sorry.
as for 0 !equaling 1, that is true :D, but at least I can say “I assumed that nobody would use zero” to cover up my mistake.
Also, Thank you for taking the time to explain the difference between N multiples and Multiples of N.
As for your second example, those expressions are used in Persian as well.
Well, as if adapting to a new numeral system is not enough, I have to learn the terminology too
@Soheils the symbols are typeset as \lfloor, \rfloor, \lceil, and \rceil in LaTeX. Wasn’t sure how to put them here, except by opening MS Word’s equation editor and pasting the symbols here.
I forgot, N!=1 can also mean “N is not equal to 1” (in many programming languages). But clearly you didn’t mean that
@MITer94
Actually, I meant exactly that. I did not mean factoriel.
Sorry. I often forget that != has no meaning outside of programming.
When I said :
The location of the exclamation mark was not an error.
What I meant was :
If n == 1, or both x and y are multiples of n : k = {(x-y)÷n} + 1
Else if n!= 1, and either x or y is not a multiple of n, then k = (x-y) ÷ n.
@Soheils oh! Oops. I thought you were being tricky or something by saying “If N factorial equals 1.” I didn’t think about “N != 1” because it didn’t make sense to me when interpreted by itself. Sorry about that.