# Check whether a large number is divisible by 53 or not

Given a large number in the form of a string **N**, the task is to check whether the number is divisible by 53 or not.

**Examples:**

Input:N = 5299947

Output:Yes

Input:N = 54

Output:No

**Approach:**

- Extract the last digit of the given string
**N**and remove it. - Multiply that digit by 37.
- Subtract the product calculated in the above step from the remaining number.
- Continue until we reduce the given string to a 3 or four digit number.
- Convert the remaining string to its corresponding integer form and check if it is divisible by 53 or not.

Below is the implementation of the above approach:

## C++

`// C++ program to check ` `// whether a number ` `// is divisible by 53 or not ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to check if the ` `// number is divisible by 53 or not ` `bool` `isDivisible(string s) ` `{ ` ` ` `int` `flag = 0; ` ` ` `while` `(s.size() > 4) { ` ` ` ` ` `int` `l = s.size() - 1; ` ` ` `int` `x = (s[l] - ` `'0'` `) * 37; ` ` ` ` ` `reverse(s.begin(), s.end()); ` ` ` `s.erase(0, 1); ` ` ` ` ` `int` `i = 0, carry = 0; ` ` ` `while` `(x) { ` ` ` `int` `d = (s[i] - ` `'0'` `) ` ` ` `- (x % 10) ` ` ` `- carry; ` ` ` `if` `(d < 0) { ` ` ` `d += 10; ` ` ` `carry = 1; ` ` ` `} ` ` ` `else` ` ` `carry = 0; ` ` ` ` ` `s[i] = (` `char` `)(d + ` `'0'` `); ` ` ` `x /= 10; ` ` ` `i++; ` ` ` `} ` ` ` ` ` `while` `(carry && i < l) { ` ` ` `int` `d = (s[i] - ` `'0'` `) - carry; ` ` ` `if` `(d < 0) { ` ` ` `d += 10; ` ` ` `carry = 1; ` ` ` `} ` ` ` `else` ` ` `carry = 0; ` ` ` ` ` `s[i] = (` `char` `)(d + ` `'0'` `); ` ` ` ` ` `i++; ` ` ` `} ` ` ` ` ` `reverse(s.begin(), s.end()); ` ` ` `} ` ` ` ` ` `int` `num = 0; ` ` ` `for` `(` `int` `i = 0; i < s.size(); i++) { ` ` ` `num = num * 10 + (s[i] - ` `'0'` `); ` ` ` `} ` ` ` ` ` `if` `(num % 53 == 0) ` ` ` `return` `true` `; ` ` ` `else` ` ` `return` `false` `; ` `} ` ` ` `// Driver Code ` `int` `main() ` `{ ` ` ` `string N = ` `"18432462191076"` `; ` ` ` ` ` `if` `(isDivisible(N)) ` ` ` `cout << ` `"Yes"` `<< endl; ` ` ` `else` ` ` `cout << ` `"No"` `<< endl; ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

**Output:**

Yes

GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details

## Recommended Posts:

- Check if any large number is divisible by 17 or not
- To check whether a large number is divisible by 7
- Check if a large number is divisible by 11 or not
- Check if a large number is divisible by 9 or not
- Check if any large number is divisible by 19 or not
- Check if a large number is divisible by 5 or not
- Check if a large number is divisible by 4 or not
- Check if a large number is divisible by 13 or not
- Check if a large number is divisible by 2, 3 and 5 or not
- Check if a large number is divisible by 3 or not
- Check if a large number is divisible by 6 or not
- Check if a large number is divisible by 8 or not
- Check if a large number is divisible by 25 or not
- Check if a large number is divisible by 20
- Check a large number is divisible by 16 or not

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.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.