Open In App

Zuckerman Numbers

Last Updated : 13 Jul, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Given an integer N, the task is to check if N is a Zuckerman Number.
 

Zuckerman Number is a number which is divisible by the product of its digits 
 

Examples: 
 

Input: N = 115 
Output: Yes 
Explanation: 
1*1*5 = 5 and 115 % 5 = 0
Input: N = 28 
Output: No 
 

 

Approach: The idea is to find the product of digits of N and check if N is divisible by its product of digits or not. If yes then the number N is a Zuckerman Number.
Below is the implementation of the above approach:
 

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>


Output

Yes

 Time Complexity: O(log10n)
 
References: OEIS 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads