Dado un número entero N , la tarea es comprobar si N es un número de Zuckerman.
El número de Zuckerman es un número que es divisible por el producto de sus dígitos
Ejemplos:
Entrada: N = 115
Salida: Sí
Explicación:
1*1*5 = 5 y 115 % 5 = 0
Entrada: N = 28
Salida: No
Enfoque: La idea es encontrar el producto de dígitos de N y verificar si N es divisible por su producto de dígitos o no. En caso afirmativo, el número N es un número de Zuckerman.
A continuación se muestra la implementación del enfoque anterior:
C++
// C++ implementation to check if N // is a Zuckerman number #include <bits/stdc++.h> using namespace std; // Function to get product of digits int getProduct(int n) { int product = 1; while (n != 0) { product = product * (n % 10); n = n / 10; } return product; } // Function to check if N is an // Zuckerman number bool isZuckerman(int n) { return n % getProduct(n) == 0; } // Driver code int main() { int n = 115; if (isZuckerman(n)) cout << "Yes"; else cout << "No"; return 0; }
Java
// Java implementation to check if N // is a Zuckerman number class GFG{ // Function to get product of digits static int getProduct(int n) { int product = 1; while (n != 0) { product = product * (n % 10); n = n / 10; } return product; } // Function to check if N is an // Zuckerman number static boolean isZuckerman(int n) { return n % getProduct(n) == 0; } // Driver code public static void main(String[] args) { int n = 115; if (isZuckerman(n)) { System.out.println("Yes"); } else { System.out.println("No"); } } } // This code is contributed by shubham
Python 3
# Python3 implementation to check if N # is a Zuckerman number # Function to get product of digits def getProduct(n): product = 1 while (n > 0): product = product * (n % 10) n = n // 10 return product # Function to check if N is an # Zuckerman number def isZuckerman(n): return n % getProduct(n) == 0 # Driver code N = 115 if (isZuckerman(N)): print("Yes") else: print("No") # This code is contributed by Vishal Maurya
C#
// C# implementation to check if N // is a Zuckerman number using System; class GFG{ // Function to get product of digits static int getProduct(int n) { int product = 1; while (n != 0) { product = product * (n % 10); n = n / 10; } return product; } // Function to check if N is an // Zuckerman number static bool isZuckerman(int n) { return n % getProduct(n) == 0; } // Driver code public static void Main(String[] args) { int n = 115; if (isZuckerman(n)) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } // This code is contributed by Rohit_ranjan
Javascript
<script> // Javascript implementation to check if N // is a Zuckerman number // Function to get product of digits function getProduct( n) { let product = 1; while (n != 0) { product = product * (n % 10); n = parseInt(n / 10); } return product; } // Function to check if N is an // Zuckerman number function isZuckerman( n) { return n % getProduct(n) == 0; } // Driver code let n = 115; if (isZuckerman(n)) { document.write("Yes"); } else { document.write("No"); } // This code is contributed by todaysgaurav </script>
Producción
Yes
Complejidad temporal: O(log 10 n)
Referencias: OEIS