Given two large or small numbers, the task is to find the last digit of the product of these two numbers.
Input: a = 1234567891233789, b = 567891233156156 Output: 4 Input: a = 123, b = 456 Output: 8
Approach: In general, the last digit of multiplication of 2 numbers a and b is the last digit of the product of the LSB of these two numbers.
For example: For a = 123 and b = 456,
the last digit of a*b
= Last digit of ((LSB of a)*(LSB of b))
= Last digit of ((3)*(6))
= Last digit of (18)
Below is the implementation of the above approach:
Time Complexity: O(1).
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Last digit of a number raised to last digit of N factorial
- Find Last Digit of a^b for Large Numbers
- Count numbers in a range with digit sum divisible by K having first and last digit different
- Count of Numbers in Range where first digit is equal to last digit of the number
- Count of N-digit numbers having digit XOR as single digit
- Find the remainder when First digit of a number is divided by its Last digit
- Count of pairs (A, B) in range 1 to N such that last digit of A is equal to the first digit of B
- Multiply large integers under large modulo
- Print all K digit repeating numbers in a very large number
- Largest palindrome which is product of two n-digit numbers
- Largest palindrome which is product of two N-digit numbers : Set 2
- Maximize big when both big and small can be exchanged
- Last digit of sum of numbers in the given range in the Fibonacci series
- Count all numbers up to N having M as the last digit
- N digit numbers having difference between the first and last digits as K
- Find a number K having sum of numbers obtained by repeated removal of last digit of K is N
- Recursive sum of digit in n^x, where n and x are very large
- Count n digit numbers not having a particular digit
- GCD of two numbers when one of them can be very large
- Sum of two large numbers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.