# Check if the number is divisible 43 or not

Given a number N, the task is to check whether the number is divisible by 43 or not.
Examples:

Input: N = 2795
Output: yes
Explanation:
43 * 65 = 2795
Input: N = 11094
Output: yes
Explanation:
43 * 258 = 11094

Approach: The divisibility test of 43 is:

1. Extract the last digit.
2. Add 13 * last digit from the remaining number obtained after removing the last digit.
3. Repeat the above steps until a two-digit number, or zero, is obtained.
4. If the two-digit number is divisible by 43, or it is 0, then the original number is also divisible by 43.

For example:

```If N = 11739

Step 1:
N = 11739
Last digit = 9
Remaining number = 1173
Resultant number = 1173 + 13*9 = 1290

Step 2:
N = 1290
Since 129 is divisible by 43 as 43 * 3 = 129

Therefore N = 11739 is also divisible by 43```

Below is the implementation of the above approach:

## C++

 `// C++ program to check whether a number` `// is divisible by 43 or not`   `#include` `#include`   `using` `namespace` `std;` `// Function to check if the number is  divisible by 43 or not ` `bool` `isDivisible(``int` `n)  ` `{` `    ``int` `d;` `    ``// While there are at least two digits ` `    ``while` `(n / 100) ` `    ``{` ` `  `        ``// Extracting the last ` `        ``d = n % 10;` ` `  `        ``// Truncating the number ` `        ``n /= 10;` ` `  `        ``// adding thirteen times the last ` `        ``// digit to the remaining number ` `        ``n = ``abs``(n+(d * 13));` `    ``}` `    ``// Finally return if the two-digit` `    ``// number is divisible by 43 or not` `    ``return` `(n % 43 == 0) ;` `}`   `// Driver Code ` `int` `main() {` `    ``int` `N = 2795;` ` `  `    ``if` `(isDivisible(N)) ` `        ``cout<<``"Yes"``<

## Java

 `// Java program to check whether a number` `// is divisible by 43 or not` `class` `GFG` `{`   `// Function to check if the number is  divisible by 43 or not ` `static` `boolean` `isDivisible(``int` `n)  ` `{` `    ``int` `d;` `    ``// While there are at least two digits ` `    ``while` `((n / ``100``) > ``0``) ` `    ``{` `  `  `        ``// Extracting the last ` `        ``d = n % ``10``;` `  `  `        ``// Truncating the number ` `        ``n /= ``10``;` `  `  `        ``// adding thirteen times the last ` `        ``// digit to the remaining number ` `        ``n = Math.abs(n+(d * ``13``));` `    ``}` `    ``// Finally return if the two-digit` `    ``// number is divisible by 43 or not` `    ``return` `(n % ``43` `== ``0``) ;` `}` ` `  `// Driver Code ` `public` `static` `void` `main(String[] args) {` `    ``int` `N = ``2795``;` `  `  `    ``if` `(isDivisible(N)) ` `        ``System.out.print(``"Yes"``);` `    ``else` `        ``System.out.print(``"No"``);` `    `  ` ``}     ` `}    ` ` `  `// This code is contributed by PrinciRaj1992`

## Python 3

 `# Python program to check whether a number` `# is divisible by 43 or not`   `# Function to check if the number is ` `# divisible by 43 or not ` `def` `isDivisible(n) : `   `    ``# While there are at least two digits ` `    ``while` `n ``/``/` `100` `: `   `        ``# Extracting the last ` `        ``d ``=` `n ``%` `10`   `        ``# Truncating the number ` `        ``n ``/``/``=` `10`   `        ``# Adding thirteen  times the last ` `        ``# digit to the remaining number ` `        ``n ``=` `abs``(n``+``(d ``*` `13``))`   `    ``# Finally return if the two-digit` `    ``# number is divisible by 43 or not` `    ``return` `(n ``%` `43` `=``=` `0``) `   `# Driver Code ` `if` `__name__ ``=``=` `"__main__"` `: ` `    `  `    ``N ``=` `2795`   `    ``if` `(isDivisible(N)): ` `        ``print``(``"Yes"``) ` `    ``else` `: ` `        ``print``(``"No"``) `

## C#

 `// C# program to check whether a number` `// is divisible by 43 or not` `using` `System; ` `        `  `class` `GFG ` `{ ` `    `  `// Function to check if the number is divisible by 43 or not ` `static` `bool` `isDivisible(``int` `n) ` `{` `    ``int` `d;` `    `  `    ``// While there are at least two digits ` `    ``while` `(n / 100 > 0) ` `    ``{`   `        ``// Extracting the last ` `        ``d = n % 10;`   `        ``// Truncating the number ` `        ``n /= 10;`   `        ``// adding thirteen times the last ` `        ``// digit to the remaining number ` `        ``n = Math.Abs(n + (d * 13));` `    ``}` `    `  `    ``// Finally return if the two-digit` `    ``// number is divisible by 43 or not` `    ``return` `(n % 43 == 0) ;` `}`   `// Driver Code ` `public` `static` `void` `Main() ` `{ ` `    ``int` `N = 2795;`   `    ``if` `(isDivisible(N)) ` `        ``Console.WriteLine(``"Yes"``); ` `    ``else` `        ``Console.WriteLine(``"No"``);     ` `} ` `}`   `// This code is contributed by AbhiThakur`

## Javascript

 ``

Output:

`Yes`

Time Complexity: O(log10N)

Auxiliary Space: O(1)

Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!