how to check whether a number is divisible by 5 or not without using % and / operator. I want a quickest algorithm for this problem.
Let's represent the number in base 2. We have:
abcdefgh*101 = ABCDEFGHIJ
or
+abcdefgh00
+ abcdefgh
----------
ABCDEFGHIJ
We are given ABCDEFGHIJ and want to find abcdefgh.
If you alternately - and + ABCDEFGH with its successive rightshift-by-2, you will get...
+ ABCDEFGH
- ABCDEF
+ ABCD
- AB
-----------
+ abcdefgh
+ abcdef
- abcdef
- abcd
+ abcd
+ ab
- ab
-----------
abcdefgh
The answer!