Check if a larger number divisible by 36

04 Jul, 2022
Given a number, check whether a given number is divisible by 36 or not. The number may be very large and may not fit in any numeric(int, long int, float, etc.) data type.Examples:  
Input : 72
Output : Yes

Input : 244
Output : No

Input : 11322134
Output : No

Input : 92567812197966231384
Output : Yes
 
A number is divisible by 36 if the number is divisible by 4 and 9  
A number is divisible by 4 if the number formed by its last 2 digits is divisible by 4A number is divisible by 9 if the sum of the digits of the number is divisible by 9
A number is divisible by 4 if the number formed by its last 2 digits is divisible by 4
A number is divisible by 9 if the sum of the digits of the number is divisible by 9
Below is the implementation based on above idea. 
C++
Java
Python3
C#
PHP
Javascript
// C++ implementation to check divisibility by 36#include <bits/stdc++.h>using namespace std; // Function to check whether a number// is divisible by 36 or notstring divisibleBy36(string num){    int l = num.length();     // null number cannot    // be divisible by 36    if (l == 0)        return "No";     // single digit number other than    // 0 is not divisible by 36    if (l == 1 && num[0] != '0')        return "No";     // number formed by the last 2 digits    int two_digit_num = (num[l-2] - '0')*10 +                        (num[l-1] - '0') ;     // if number is not divisible by 4    if (two_digit_num%4 != 0)        return "No";     // number is divisible by 4 calculate    // sum of digits    int sum = 0;    for (int i=0; i<l; i++)        sum += (num[i] - '0');     // sum of digits is not divisible by 9    if (sum%9 != 0)        return "No";     // number is divisible by 4 and 9    // hence, number is divisible by 36    return "Yes";} // Driver programint main(){    string num = "92567812197966231384";    cout << divisibleBy36(num);    return 0;}
// Java program to find if a number is// divisible by 36 or notclass IsDivisible{    // Function to check whether a number    // is divisible by 36 or not    static boolean divisibleBy36(String num)    {        int l = num.length();              // null number cannot        // be divisible by 36        if (l == 0)            return false;              // single digit number other than        // 0 is not divisible by 36        if (l == 1 && num.charAt(0) != '0')            return false;              // number formed by the last 2 digits        int two_digit_num = (num.charAt(l-2) - '0')*10 +                            (num.charAt(l-1) - '0') ;              // if number is not divisible by 4        if (two_digit_num%4 != 0)            return false;              // number is divisible by 4 calculate        // sum of digits        int sum = 0;        for (int i=0; i<l; i++)            sum += (num.charAt(i) - '0');              // sum of digits is not divisible by 9        if (sum%9 != 0)            return false;              // number is divisible by 4 and 9        // hence, number is divisible by 36        return true;    }     // main function    public static void main (String[] args)    {        String num = "92567812197966231384";        if(divisibleBy36(num))            System.out.println("Yes");        else            System.out.println("No");    }}
# Python 3 implementation to# check divisibility by 36 # Function to check whether a# number is divisible by# 36 or notdef divisibleBy36(num) :    l = len(num)     # null number cannot    # be divisible by 36    if (l == 0) :        return ("No")     # single digit number other    # than 0 is not divisible    # by 36    if (l == 1 and num[0] != '0') :        return ("No")     # number formed by the    # last 2 digits    two_digit_num = (((int)(num[l - 2])) *                    10 +(int)(num[l - 1]))     # if number is not    # divisible by 4    if (two_digit_num%4 != 0) :        return "No"     # number is divisible    # by 4 calculate sum    # of digits    sm = 0    for i in range(0,l) :        sm = sm + (int)(num[i])     # sum of digits is not    # divisible by 9    if (sm%9 != 0) :        return ("No")     # Number is divisible    # by 4 and 9 hence,    # number is divisible    # by 36    return ("Yes") # Driver programnum = "92567812197966231384"print(divisibleBy36(num)) # This code is contributed by Nikita Tiwari.
// C# program to find if a number is// divisible by 36 or notusing System; class GFG {         // Function to check whether    // a number is divisible by    // 36 or not    static bool divisibleBy36(String num)    {        int l = num.Length;             // null number cannot        // be divisible by 36        if (l == 0)            return false;             // single digit number other than        // 0 is not divisible by 36        if (l == 1 && num[0] != '0')            return false;             // number formed by the last        // 2 digits        int two_digit_num = (num[l-2] - '0') * 10                             + (num[l-1] - '0') ;             // if number is not divisible by 4        if (two_digit_num % 4 != 0)            return false;             // number is divisible by 4 calculate        // sum of digits        int sum = 0;        for (int i = 0; i < l; i++)            sum += (num[i] - '0');             // sum of digits is not divisible by 9        if (sum % 9 != 0)            return false;             // number is divisible by 4 and 9        // hence, number is divisible by 36        return true;    }     // main function    public static void Main ()    {        String num = "92567812197966231384";                 if(divisibleBy36(num))            Console.Write("Yes");        else            Console.Write("No");    }} // This code is contributed by parashar.
<?php// PHP implementation to// check divisibility by 36 // Function to check whether a number// is divisible by 36 or notfunction divisibleBy36($num){    $l = strlen($num);     // null number cannot    // be divisible by 36    if ($l == 0)        return "No";     // single digit number other than    // 0 is not divisible by 36    if ($l == 1 && $num[0] != '0')        return "No";     // number formed by the    // last 2 digits    $two_digit_num = ($num[$l - 2] - '0') * 10 +                            ($num[$l - 1] - '0') ;     // if number is not    // divisible by 4    if ($two_digit_num%4 != 0)        return "No";     // number is divisible by 4    // calculate sum of digits    $sum = 0;    for ($i = 0; $i < $l; $i++)        $sum += ($num[$i] - '0');     // sum of digits is not    // divisible by 9    if ($sum % 9 != 0)        return "No";     // number is divisible by 4 and 9    // hence, number is divisible by 36    return "Yes";} // Driver Code$num = "92567812197966231384";echo(divisibleBy36($num)); // This code is contributed by Ajit.?>
<script>// Javascript implementation to// check divisibility by 36 // Function to check whether a number// is divisible by 36 or notfunction divisibleBy36(num){    let l = num.length;     // null number cannot    // be divisible by 36    if (l == 0)        return "No";     // single digit number other than    // 0 is not divisible by 36    if (l == 1 && num[0] != '0')        return "No";     // number formed by the    // last 2 digits    let two_digit_num = (num[l - 2] - '0') * 10 +                            (num[l - 1] - '0') ;     // if number is not    // divisible by 4    if (two_digit_num%4 != 0)        return "No";     // number is divisible by 4    // calculate sum of digits    let sum = 0;    for (let i = 0; i < l; i++)        sum += (num[i] - '0');     // sum of digits is not    // divisible by 9    if (sum % 9 != 0)        return "No";     // number is divisible by 4 and 9    // hence, number is divisible by 36    return "Yes";} // Driver Codelet num = "92567812197966231384";document.write(divisibleBy36(num)); // This code is contributed by _saurabh_jaiswal.</script>
Yes
Time Complexity: O(n) 
Method: Checking given number is divisible by 36 or not by using modulo division operator “%”.  
Python3
Javascript
# Python code# To check whether the given number is divisible by 36 or not #inputn=72# the above input can also be given as n=input() -> taking input from user# finding given number is divisible by 36 or notif int(n)%36==0:  print("Yes")else:  print("No")     # this code is contributed by gangarajula laxmi
<script>      // JavaScript code for the above approach      // To check whether the given number is divisible by 36 or not       //input      n = 72      // the above input can also be given as n=input() -> taking input from user      // finding given number is divisible by 36 or not      if (n % 36 == 0)          document.write("Yes")      else          document.write("No")  // This code is contributed by Potta Lokesh  </script>
Yes
This article is contributed by Ayush Jauhari. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above. 
parashar
jit_t
_saurabh_jaiswal
laxmigangarajula03
lokeshpotta20
divisibility
large-numbers
number-digits
Mathematical
Mathematical
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Algorithm to solve Rubik's Cube
Merge two sorted arrays with O(1) extra space
Program to print prime numbers from 1 to N.
Find next greater number with same set of digits
Segment Tree | Set 1 (Sum of given range)
Check if a number is Palindrome
Count ways to reach the n'th stair
Fizz Buzz Implementation
Count all possible paths from top left to bottom right of a mXn matrix
Product of Array except itself