numeros de ronda

Dado un número entero N , la tarea es verificar si N es un número de Rhonda en base 10.

Los números de Rhonda en base 10 son números si el producto de sus dígitos es igual a 10*Suma de factores primos de N (incluida la multiplicidad). 
 

Ejemplos:  

Entrada: N = 1568 
Salida: Sí 
Explicación: 
factorización prima de 1568 = 2 5 * 7 2
Suma de factores primos = 2*5+7*2=24. 
Producto de dígitos de 1568 = 1*5*6*8=240 = 10*24. 
Por lo tanto, 1568 es un número de Rhonda en base 10.

Entrada: N = 28 
Salida: No 

Enfoque: La idea es encontrar la suma de todos los factores primos de N y verificar si diez veces la suma de los factores primos de N es igual al producto de los dígitos de N o no.

A continuación se muestra la implementación del enfoque anterior:

C++

// 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

// 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

# 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#

// 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

Javascript

<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>
Producción: 

Yes

Complejidad del tiempo: O(sqrt(N))

Referencias: OEIS
 

Publicación traducida automáticamente

Artículo escrito por spp____ y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *