Given an integer N, the task is to check if N is a Rhonda numbers to base 10.
Rhonda numbers to base 10 are numbers if the product of its digits equals 10*Sum of prime factors of N (including multiplicity).
Examples:
Input: N = 1568
Output: Yes
Explanation:
1568’s prime factorization = 25 * 72.
Sum of prime factors = 2*5+7*2=24.
Product of digits of 1568 = 1*5*6*8=240 = 10*24.
Hence 1568 is a Rhonda number to base 10.Input: N = 28
Output: No
Approach: The idea is to find the sum of all prime factors of N and check if ten times of Sum of prime factors of N is equal to the product of digits of N or not.
Below is the implementation of the above approach:
// C++ implementation to check if N // is a Rhonda number #include <bits/stdc++.h> using namespace std;
// Function to find the // product of digits int getProduct( int n)
{ int product = 1;
while (n != 0) {
product = product * (n % 10);
n = n / 10;
}
return product;
} // Function to find sum of all prime // factors of a given number N int sumOfprimeFactors( int n)
{ int sum = 0;
// add the number of
// 2s that divide n
while (n % 2 == 0) {
sum += 2;
n = n / 2;
}
// N must be odd at this
// point. So we can skip
// one element
for ( int i = 3; i <= sqrt (n);
i = i + 2) {
// While i divides n,
// add i and divide n
while (n % i == 0) {
sum += i;
n = n / i;
}
}
// Condition to handle the case when N
// is a prime number greater than 2
if (n > 2)
sum += n;
return sum;
} // Function to check if n // is Rhonda number bool isRhondaNum( int N)
{ return 10 * sumOfprimeFactors(N) == getProduct(N);
} // Driver code int main()
{ int n = 1568;
if (isRhondaNum(n))
cout << "Yes" ;
else
cout << "No" ;
return 0;
} |
// Java program to check if N // is a Rhonda number import java.util.*;
import java.lang.*;
// import Math; class GFG{
// Function to find the // 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 find sum of all prime // factors of a given number N static int sumOfprimeFactors( int n)
{ int sum = 0 ;
// Add the number of
// 2s that divide n
while (n % 2 == 0 )
{
sum += 2 ;
n = n / 2 ;
}
// N must be odd at this
// point. So we can skip
// one element
for ( int i = 3 ; i <= Math.sqrt(n);
i = i + 2 )
{
// While i divides n,
// add i and divide n
while (n % i == 0 )
{
sum += i;
n = n / i;
}
}
// Condition to handle the case when N
// is a prime number greater than 2
if (n > 2 )
sum += n;
return sum;
} // Function to check if n // is Rhonda number static boolean isRhondaNum( int N)
{ return ( 10 * sumOfprimeFactors(N) ==
getProduct(N));
} // Driver Code public static void main(String[] args)
{ // Given Number n
int n = 1568 ;
if (isRhondaNum(n))
{
System.out.println( "Yes" );
}
else
{
System.out.println( "No" );
}
} } // This code is contributed by vikas_g |
# Python3 implementation to check # if N is a Rhonda number import math
# Function to find the # product of digits def getProduct(n):
product = 1
while (n ! = 0 ):
product = product * (n % 10 )
n = n / / 10
return product
# Function to find sum of all prime # factors of a given number N def sumOfprimeFactors(n):
Sum = 0
# Add the number of
# 2s that divide n
while (n % 2 = = 0 ):
Sum + = 2
n = n / / 2
# N must be odd at this
# point. So we can skip
# one element
for i in range ( 3 , int (math.sqrt(n)) + 1 , 2 ):
# While i divides n,
# add i and divide n
while (n % i = = 0 ):
Sum + = i
n = n / / i
# Condition to handle the case when N
# is a prime number greater than 2
if (n > 2 ):
Sum + = n
return Sum
# Function to check if n # is Rhonda number def isRhondaNum(N):
return bool ( 10 * sumOfprimeFactors(N) = =
getProduct(N))
# Driver code n = 1568
if (isRhondaNum(n)):
print ( "Yes" )
else :
print ( "No" )
# This code is contributed by divyeshrabadiya07 |
// C# implementation to check if N // is a Rhonda number using System;
class GFG{
// Function to find the // 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 find sum of all prime // factors of a given number N static int sumOfprimeFactors( int n)
{ int sum = 0;
// Add the number of
// 2s that divide n
while (n % 2 == 0)
{
sum += 2;
n = n / 2;
}
// N must be odd at this
// point. So we can skip
// one element
for ( int i = 3; i <= Math.Sqrt(n);
i = i + 2)
{
// While i divides n,
// add i and divide n
while (n % i == 0)
{
sum += i;
n = n / i;
}
}
// Condition to handle the case when N
// is a prime number greater than 2
if (n > 2)
sum += n;
return sum;
} // Function to check if n // is Rhonda number static bool isRhondaNum( int N)
{ return (10 * sumOfprimeFactors(N) ==
getProduct(N));
} // Driver code public static void Main(String []args)
{ int n = 1568;
if (isRhondaNum(n))
{
Console.WriteLine( "Yes" );
}
else
{
Console.WriteLine( "No" );
}
} } // This code is contributed by vikas_g |
<script> // Javascript program to check if N // is a Rhonda number // Function to find the
// product of digits
function getProduct( n)
{
let product = 1;
while (n != 0)
{
product = product * (n % 10);
n = parseInt(n / 10);
}
return product;
}
// Function to find sum of all prime
// factors of a given number N
function sumOfprimeFactors( n) {
let sum = 0;
// Add the number of
// 2s that divide n
while (n % 2 == 0) {
sum += 2;
n = parseInt(n / 2);
}
// N must be odd at this
// point. So we can skip
// one element
for ( let i = 3; i <= Math.sqrt(n); i = i + 2)
{
// While i divides n,
// add i and divide n
while (n % i == 0)
{
sum += i;
n = parseInt(n / i);
}
}
// Condition to handle the case when N
// is a prime number greater than 2
if (n > 2)
sum += n;
return sum;
}
// Function to check if n
// is Rhonda number
function isRhondaNum( N) {
return (10 * sumOfprimeFactors(N) == getProduct(N));
}
// Driver Code
// Given Number n
let n = 1568;
if (isRhondaNum(n)) {
document.write( "Yes" );
} else {
document.write( "No" );
}
// This code is contributed by todaysgaurav </script> |
Yes
Time Complexity: O(sqrt(N))
References: OEIS