VOOZH about

URL: https://www.geeksforgeeks.org/dsa/divisibility-by-12-for-a-large-number/

⇱ Divisibility by 12 for a large number - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Divisibility by 12 for a large number

Last Updated : 30 Jan, 2023

Given a large number, the task is to check whether the number is divisible by 12 or not.

Examples : 

Input : 12244824607284961224
Output : Yes

Input : 92387493287593874594898678979792
Output : No

Method 1: This is a very simple approach. if a number is divisible by 4 and 3 then the number is divisible by 12. 

Point 1. If the last two digits of the number are divisible by 4 then the number is divisible by 4. Please see divisibility by 4 for large numbers for details. 
Point 2. if the sum of all digits of a number is divided by 3 then the number is divisible by 3. Please see divisibility by 3 for large numbers for details. 


Output
Yes

Time Complexity: O(N), where N is the length of the given string.
Auxiliary Space: O(1)

Method: Checking given number is divisible by 12 or not by using the modulo division operator "%".  


Output
No

Time Complexity: O(1)
Auxiliary Space: O(1)

Comment