# Check if a larger number divisible by 36

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
```

## Recommended: Please solve it on “PRACTICE” first, before moving on to the solution.

A number is divisible by 36 if the number is divisible by 4 and 9

Below is the implementation based on above idea.

## C++

 `// C++ implementation to check divisibility by 36 ` `#include ` `using` `namespace` `std; ` ` `  `// Function to check whether a number ` `// is divisible by 36 or not ` `string 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'``) ` `        ``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

## Java

 `// Java program to find if a number is ` `// divisible by 36 or not ` `class` `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

## Python3

 `# Python 3 implementation to ` `# check divisibility by 36 ` ` `  `# Function to check whether a ` `# number is divisible by  ` `# 36 or not ` `def` `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 program ` `num ``=` `"92567812197966231384"` `print``(divisibleBy36(num)) ` ` `  `# This code is contributed by Nikita Tiwari. `

## C#

 `// C# program to find if a number is ` `// divisible by 36 or not ` `using` `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'``) ` `            ``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

 ` `

Output:

```Yes
```

Time Complexity: O(n)

This article is contributed by Ayush Jauhari. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

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.

My Personal Notes arrow_drop_up

Improved By : parashar, jit_t

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.