Given a number, the task is to check if number is divisible by 25. The input number may be large and it may not be possible to store even if we use long long int.

Examples:

Input : n = 56945250 Output : Yes Input : n = 1234567589333100 Output : Yes Input : n = 3635883959606670431112222 Output : No

Since input number may be very large, we cannot use n % 25 to check if a number is divisible by 25 or not, especially in languages like C/C++. The idea is based on following fact.

A number is divisible by 25 if its digits last two digits will be 0 or divisible by 25 .

**Illustration: **

For example, let us consider 769575 Number formed by last two digits is = 75 Since 75 is divisible by 25 , answer is YES.

Let us consider 5325, we can write it as 5325 = 5*1000 + 3*100 + 2*10 + 5 The proof is based on below observation: Remainder of 10i divided by 25 is 0 if i greater than or equal to two. Note than 100, 1000, ... etc lead to remainder 0 when divided by 25. So remainder of " 5*1000 + 3*100 + 2*10 + 5" divided by 25 is equivalent to remainder of following : 0 + 0 + 20 + 5 = 25 Since 25 is divisible by 25, answer is yes.

## C++

`// C++ program to find if a number is ` `// divisible by 25 or not ` `#include<bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to find that number divisible ` `// by 25 or not. ` `bool` `isDivisibleBy25(string str) ` `{ ` ` ` `// If length of string is single digit then ` ` ` `// it's not divisible by 25 ` ` ` `int` `n = str.length(); ` ` ` `if` `(n == 1) ` ` ` `return` `false` `; ` ` ` ` ` `return` `( (str[n-1]-` `'0'` `== 0 && ` ` ` `str[n-2]-` `'0'` `== 0) || ` ` ` `((str[n-2]-` `'0'` `)*10 + (str[n-1]-` `'0'` `))%25 == 0 ); ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `string str = ` `"76955"` `; ` ` ` `isDivisibleBy25(str)? cout << ` `"Yes"` `: ` ` ` `cout << ` `"No "` `; ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find if a number is ` `// divisible by 25 or not ` `class` `IsDivisible ` `{ ` ` ` `// Function to find that number divisible ` ` ` `// by 25 or not. ` ` ` `static` `boolean` `isDivisibleBy25(String str) ` ` ` `{ ` ` ` `// If length of string is single digit then ` ` ` `// it's not divisible by 25 ` ` ` `int` `n = str.length(); ` ` ` `if` `(n == ` `1` `) ` ` ` `return` `false` `; ` ` ` ` ` `return` `( (str.charAt(n-` `1` `)-` `'0'` `== ` `0` `&& ` ` ` `str.charAt(n-` `2` `)-` `'0'` `== ` `0` `) || ` ` ` `((str.charAt(n-` `2` `)-` `'0'` `)*` `10` `+ (str.charAt(n-` `1` `)-` `'0'` `))%` `25` `== ` `0` `); ` ` ` `} ` ` ` ` ` `// main function ` ` ` `public` `static` `void` `main (String[] args) ` ` ` `{ ` ` ` `String str = ` `"76955"` `; ` ` ` `if` `(isDivisibleBy25(str)) ` ` ` `System.out.println(` `"Yes"` `); ` ` ` `else` ` ` `System.out.println(` `"No"` `); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## Python3

`# Python 3 program to find if ` `# a number is divisible by 25 ` `# or not ` ` ` `# Function to find that ` `# number divisible by 25 or not. ` `def` `isDivisibleBy25(st) : ` ` ` ` ` `# If length of string is ` ` ` `# single digit then it's ` ` ` `# not divisible by 25 ` ` ` `n ` `=` `len` `(st) ` ` ` `if` `(n ` `=` `=` `1` `) : ` ` ` `return` `False` ` ` ` ` `return` `((` `int` `)(st[n` `-` `1` `]) ` `=` `=` `0` `and` `((` `int` `)(st[n` `-` `2` `])` `=` `=` `0` `) ` `or` ` ` `((` `int` `)(st[n` `-` `2` `])` `*` `10` `+` `(` `int` `)(st[n` `-` `1` `])` `%` `25` `=` `=` `0` `)) ` ` ` `# Driver code ` `st ` `=` `"76955"` `if` `(isDivisibleBy25(st)) : ` ` ` `print` `(` `"Yes"` `) ` `else` `: ` ` ` `print` `(` `"No"` `) ` ` ` ` ` `# This code is contributed by Nikita Tiwari. ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find if a number ` `// is divisible by 25 or not ` `using` `System; ` ` ` `class` `IsDivisible ` `{ ` ` ` `// Function to find that number ` ` ` `// divisible by 25 or not. ` ` ` `static` `bool` `isDivisibleBy25(String str) ` ` ` `{ ` ` ` `// If length of string is single digit then ` ` ` `// then it's not divisible by 25 ` ` ` `int` `n = str.Length; ` ` ` `if` `(n == 1) ` ` ` `return` `false` `; ` ` ` ` ` `return` `((str[n - 1] - ` `'0'` `== 0 && ` ` ` `str[n - 2] - ` `'0'` `== 0) || ` ` ` `((str[n - 2] - ` `'0'` `) * 10 + ` ` ` `(str[n - 1] - ` `'0'` `)) % 25 == 0); ` ` ` `} ` ` ` ` ` `// Driver Code ` ` ` `public` `static` `void` `Main () ` ` ` `{ ` ` ` `String str = ` `"76955"` `; ` ` ` `if` `(isDivisibleBy25(str)) ` ` ` `Console.Write(` `"Yes"` `); ` ` ` `else` ` ` `Console.Write(` `"No"` `); ` ` ` `} ` `} ` ` ` `// This code is contributed by Nitin Mittal ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to find if a number ` `// is divisible by 25 or not ` ` ` `// Function to find that number ` `// divisible by 25 or not. ` `function` `isDivisibleBy25(` `$str` `) ` `{ ` ` ` ` ` `// If length of string ` ` ` `// is single digit then ` ` ` `// it's not divisible by 25 ` ` ` `$n` `= ` `strlen` `(` `$str` `); ` ` ` `if` `(` `$n` `== 1) ` ` ` `return` `false; ` ` ` ` ` `return` `( (` `$str` `[` `$n` `- 1] -` `'0'` `== 0 && ` ` ` `$str` `[` `$n` `- 2] -` `'0'` `== 0) || ` ` ` `((` `$str` `[` `$n` `- 2] -` `'0'` `) * 10 + ` ` ` `(` `$str` `[` `$n` `- 1] - ` `'0'` `)) % 25 == 0 ); ` `} ` ` ` `// Driver code ` `$str` `= ` `"76955"` `; ` `$x` `= isDivisibleBy25(` `$str` `) ? ` `"Yes"` `: ` `"No "` `; ` `echo` `(` `$x` `); ` ` ` `// This code is contributed by Ajit. ` `?> ` |

*chevron_right*

*filter_none*

Output:

No

This article is contributed by ** DANISH_RAZA **. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

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.

## Recommended Posts:

- Check if a large number is divisible by 11 or not
- Check if a large number is divisible by 3 or not
- Check if a large number is divisible by 8 or not
- Check if a large number is divisible by 6 or not
- Check if a large number is divisible by 9 or not
- Check if a large number is divisible by 5 or not
- Check a large number is divisible by 16 or not
- Check if a large number is divisible by 13 or not
- Check if the large number formed is divisible by 41 or not
- Check if any large number is divisible by 19 or not
- Check if any large number is divisible by 17 or not
- Check if a large number is divisible by 2, 3 and 5 or not
- Check if a large number is divisible by 75 or not
- Check whether a large number is divisible by 53 or not
- Check if a large number is divisible by 4 or not
- Check if a large number is divisible by a number which is a power of 2
- To check whether a large number is divisible by 7
- Check if a large number is divisible by 20
- Check if any permutation of a large number is divisible by 8
- Given a large number, check if a subsequence of digits is divisible by 8