Check if a large number is divisible by 20
Given a number, the task is to check if number is divisible by 20. The input number may be large and it may not be possible to store long long int and it may be very large number then we use the string.
Examples:
Input : 7575680 Output : Yes Input : 987985865687690 Output : No
A number is divisible by 20 if it is divisible by 5 and 4. We can check if a number is divisible by 4 by checking if last two digits are divisible by 4. We can check for divisibility by 5 by checking last digit. Also, if the last digit of a number is zero and the second last digit is a multiple of 2 then the number is divisible by 20.
C++
// CPP program to check if a large number // is divisible by 20. #include <iostream> using namespace std; bool divisibleBy20(string num) { // Get number with last two digits int lastTwoDigits = stoi(num.substr(num.length() - 2, num.length() - 1)); // Check if the number formed by last two // digits is divisible by 5 and 4. return ((lastTwoDigits % 5 == 0) && (lastTwoDigits % 4 == 0)); } int main() { string num = "63284689320"; if (divisibleBy20(num)) cout << "Yes" << endl; else cout << "No" << endl; return 0; } |
Java
// Java program to check if a large n // number is divisible by 20. import java.io.*; class GFG { static Boolean divisibleBy20(String num) { // Get number with last two digits int lastTwoDigits = Integer.parseInt(num.substring(num.length() - 2, num.length() )); // Check if the number formed by last two // digits is divisible by 5 and 4. return ((lastTwoDigits % 5 == 0) && (lastTwoDigits % 4 == 0)); } // Driver Program public static void main (String[] args) { String num = "63284689320"; if (divisibleBy20(num) == true) System.out.println("Yes"); else System.out.println("No"); } } // This code is contributed by Gitanjali. |
Python3
# Python3 program to check if a large # number is divisible by 20. import math def divisibleBy20(num): # Get number with last two digits lastTwoDigits = int(num[-2:]) # Check if the number formed by last two # digits is divisible by 5 and 4. return ((lastTwoDigits % 5 == 0 and lastTwoDigits % 4 == 0)) # driver code num = "63284689320"if (divisibleBy20(num) == True): print("Yes") else: print("No") # This code is contributed by Gitanjali. |
C#
// C# program to check if a large // 'n' number is divisible by 20. using System; using System.Text; class GFG { static bool divisibleBy20(String num) { // Get number with last two digits int lastTwoDigits = Int32.Parse(num.Substring(2)); // Check if the number formed // by last two digits is // divisible by 5 and 4. return ((lastTwoDigits % 5 == 0) && (lastTwoDigits % 4 == 0)); } // Driver Code static public void Main () { String num = "63284689320"; if (divisibleBy20(num) == true) Console.Write("Yes"); else Console.Write("No"); } } // This code is contributed by Raj |
PHP
<?php // PHP program to check // if a large number is // divisible by 20. function divisibleBy20($num) { // Get number with // last two digits $lastTwoDigits = intval(substr($num, (strlen($num) - 2), 2)); // Check if the number // formed by last two // digits is divisible // by 5 and 4. return (($lastTwoDigits % 5 == 0) && ($lastTwoDigits % 4 == 0)); } // Driver Code $num = "63284689320"; if (divisibleBy20($num)) echo "Yes"; else echo "No"; // This code is contributed by mits. ?> |
Yes
Recommended Posts:
- Check if a large number is divisible by 75 or not
- To check whether a large number is divisible by 7
- Check a large number is divisible by 16 or not
- Check if a large number is divisible by 25 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 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 6 or not
- Check if a large number is divisible by 8 or not
- Check if a large number is divisible by 4 or not
- Check if a large number is divisible by 3 or not
- Check if a large number is divisible by 11 or not
- Check if any large number is divisible by 17 or not
- Check if a large number is divisible by 9 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.



