It is very easy to calculate small numbers which are divisible by Eleven, like 11, 22, 33, 121 and so on. But What about Large numbers? like 188452 or 31415 Yes, This is where we stuck.Let’s find A Number Divisible By 11 (Eleven) or Not
Here comes the easy way to calculate a number is divisible by Eleven or not. Just take the alternating sum of the digits of that number is the sum is divisible by 11 then the number also divisible by eleven.
Example ,
The number N = 188452
Alternating sum of the digits of N is Sum = 1 – 8 + 8 – 4 + 5 – 2 = 0
So, here Sum = 0, and we all know that 0 is divisible by 11.
Another Example ,
The Number N = 31415
Alternating sum of the digits of N is Sum = 3 – 1 + 4 – 1 + 5 = 10
So, here Sum = 10, and we all know that 10 isn’t divisible by 11.
Still can believe that it is that easy sit with a calculator and start calculating it .
This tricks is very useful for you mathematical problem solving and you can find the problem in programming contest also.
Math behind the fact :
This curious fact can be easily shown using modular arithmetic. Since 10n is congruent
to (-1)n mod 11, we see that 1, 100, 10000, 1000000, etc. have remainders 1 when divided by 11,
and 10, 1000, 10000, etc. have remainders (-1) when divided by 11. Thus
2728 = 2 * 1000 + 7 * 100 + 2 * 10 + 8,
so its remainder when divided by 11 is just 2(-1) + 7(1) + 2(-1) + 8(1), the alternating sum of the digits. (It’s sum is the negative of what we found above because the alternation here begins with a -1.) But either way, if this alternating sum is divisible by 11, then so is the original number.
In fact, our observation shows more: that in fact when we take the alternating sum of the digits read from right to left (so that the sign of the units digit is always positive), then we obtain N mod 11.
Programming Problems:
Divisible (HackerEarth)
Remove duplicate elements from sorted Array
Given a sorted array a[] of size n, delete all the duplicated elements from a[] & modify the array such that only distinct elements should be present there. Note:1. Don't use set or HashMap to solve the problem.2....
Maximum Subarray Sum | Kadane’s Algorithm | Array
Kadane's Algorithm is one of the simplest algorithm in computer programming.The problems of kadanes's algorithm is frequently asked on coding interviews and various programming contests. This is the first post of the Kadane's Algorithm series and I will discuss about...
Codesignal Intro Arcade 01 Add Solution
Problem Name : Add Problem Statement : Write a function that returns the sum of two numbers. Example For param1 = 1 and param2 = 2, the output should be solution(param1, param2) = 3. Editorial : This is the most easy problem off CodeSignal. You have to...
UVA Very Easy Problem List For Beginner (Part 2)
Hey I’m Masudur Rahman Sourav. I’m studying in Mawlana Bhashani Science and Technology University at the Department of Information and Communication Technology. Currently I’m start solving UVA(Online Judge) problems and I found some very easy problem for you. You can...
UVA Very Easy Problem List For Beginner (Part 1)
Hey I’m Masudur Rahman Sourav. I’m studying in Mawlana Bhashani Science and Technology University at the Department of Information and Communication Technology. Currently I’m start solving UVA(Online Judge) problems and I found some very easy problem for you. You can...