Dado un número, la tarea es verificar si el número es divisible por 20. El número de entrada puede ser grande y puede que no sea posible almacenar int largo y puede ser un número muy grande, entonces usamos la string.
Ejemplos:
Input : 7575680 Output : Yes Input : 987985865687690 Output : No
Un número es divisible por 20 si es divisible por 5 y 4. Podemos comprobar si un número es divisible por 4 comprobando si los dos últimos dígitos son divisibles por 4 . Podemos comprobar la divisibilidad por 5 comprobando el último dígito . Además, si el último dígito de un número es cero y el penúltimo dígito es un múltiplo de 2, entonces el número es divisible por 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. ?>
Javascript
<script> // Javascript program to check // if a large number is // divisible by 20. function divisibleBy20(num) { // Get number with // last two digits let lastTwoDigits = parseInt(num.slice(-2, num.length)) console.log(num.slice(-2, 1)) // Check if the number // formed by last two // digits is divisible // by 5 and 4. return ((lastTwoDigits % 5 == 0) && (lastTwoDigits % 4 == 0)) } // Driver Code let num = "63284689320"; if (divisibleBy20(num)) document.write("Yes"); else document.write("No"); // This code is contributed by _saurabh_jaiswal. </script>
Producción
Yes
Método: Comprobación de que el número dado es divisible por 20 o no utilizando el operador de división de módulo «%».
C++
#include <iostream> using namespace std; int main() { // input number long int num = 987985865687690; // finding given number is divisible by 20 or not if (num % 20 == 0) { cout<<"Yes"; } else { cout<<"No"; } return 0; } // This code is contributed by laxmigangarajula03
Java
// Java code for the above approach // To check whether the given number is divisible by 20 or // not import java.math.BigInteger; class GFG { public static void main(String[] args) { // input number BigInteger num = new BigInteger("987985865687690"); // finding given number is divisible by 20 or not if (num.mod(new BigInteger("20")) .equals(new BigInteger("0"))) { System.out.println("Yes"); } else { System.out.println("No"); } } } // This code is contributed by phasing17
Python3
# Python code # To check whether the given number is divisible by 20 or not #input n=987985865687690 # the above input can also be given as n=input() -> taking input from user # finding given number is divisible by 20 or not if int(n)%20==0: print("Yes") else: print("No") # this code is contributed by gangarajula laxmi
C#
// C# code for the above approach // To check whether the given number is divisible by 20 or // not using System; public class GFG { static public void Main() { // input number long num = 987985865687690; // finding given number is divisible by 20 or not if (num % 20 == 0) { Console.Write("Yes"); } else { Console.Write("No"); } } } // This code is contributed by laxmigangarajula03
Javascript
<script> // JavaScript code for the above approach // To check whether the given number is divisible by 20 or not //input var n = 987985865687690 // the above input can also be given as n=input() -> taking input from user // finding given number is divisible by 20 or not if (n % 20 == 0) document.write("Yes") else document.write("No") // This code is contributed by Potta Lokesh </script>
Producción
No