Zuckerman Numbers
Last Updated :
13 Jul, 2021
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++
#include <bits/stdc++.h>
using namespace std;
int getProduct( int n)
{
int product = 1;
while (n != 0) {
product = product * (n % 10);
n = n / 10;
}
return product;
}
bool isZuckerman( int n)
{
return n % getProduct(n) == 0;
}
int main()
{
int n = 115;
if (isZuckerman(n))
cout << "Yes" ;
else
cout << "No" ;
return 0;
}
|
Java
class GFG{
static int getProduct( int n)
{
int product = 1 ;
while (n != 0 )
{
product = product * (n % 10 );
n = n / 10 ;
}
return product;
}
static boolean isZuckerman( int n)
{
return n % getProduct(n) == 0 ;
}
public static void main(String[] args)
{
int n = 115 ;
if (isZuckerman(n))
{
System.out.println( "Yes" );
}
else
{
System.out.println( "No" );
}
}
}
|
Python 3
def getProduct(n):
product = 1
while (n > 0 ):
product = product * (n % 10 )
n = n / / 10
return product
def isZuckerman(n):
return n % getProduct(n) = = 0
N = 115
if (isZuckerman(N)):
print ( "Yes" )
else :
print ( "No" )
|
C#
using System;
class GFG{
static int getProduct( int n)
{
int product = 1;
while (n != 0)
{
product = product * (n % 10);
n = n / 10;
}
return product;
}
static bool isZuckerman( int n)
{
return n % getProduct(n) == 0;
}
public static void Main(String[] args)
{
int n = 115;
if (isZuckerman(n))
{
Console.WriteLine( "Yes" );
}
else
{
Console.WriteLine( "No" );
}
}
}
|
Javascript
<script>
function getProduct( n) {
let product = 1;
while (n != 0) {
product = product * (n % 10);
n = parseInt(n / 10);
}
return product;
}
function isZuckerman( n) {
return n % getProduct(n) == 0;
}
let n = 115;
if (isZuckerman(n)) {
document.write( "Yes" );
} else {
document.write( "No" );
}
</script>
|
Time Complexity: O(log10n)
References: OEIS
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...