Encuentre el número de factores de N cuando se da la ubicación de sus dos factores cuyo producto es N

Dados a y b que representa la ubicación de dos factores de N cuyo producto es igual al número N cuando los factores están ordenados en orden ascendente. La tarea es encontrar el número total de factores de N.
Ejemplos: 
 

Entrada: a = 2, b = 3 
Salida:
N = 6 
factores son {1, 2, 3, 6} 
Número de factores son 4
Entrada: a = 13, b = 36 
Salida: 48 
 

Enfoque: La solución se basa en la observación. 
Suponga N = 50 . Entonces N tiene 6 factores 1, 2, 5, 10, 25 y 50. Al multiplicar 1 y 50 siempre dará el valor 50( N ). Además, al multiplicar 2 y 25 nos da el valor N, de manera similar al multiplicar 5 y 10 obtenemos el valor N. Entonces, aquí podemos ver que al multiplicar dos factores cuando están ordenados en orden creciente da el valor N. La multiplicación debe hacerse de la siguiente manera: el 1.er factor y el último factor de la multiplicación dan N, el 2.º factor y el 2.º último factor de la multiplicación dan N y así sucesivamente.
Con este patrón, podemos encontrar una forma de calcular el número de factores. Digamos que el primer y cuarto factor en la multiplicación da N. Esto significa que hay 4 factores (primero, segundo, tercero y cuarto). Si el producto del segundo y tercer factor da N, entonces podemos decir que debe haber un factor en la primera posición y en la cuarta posición. 
Por lo tanto, el número de factores será igual a a + b – 1 .
A continuación se muestra la implementación del enfoque anterior: 
 

C++

// C++ program to implement
// the above problem
#include <bits/stdc++.h>
using namespace std;
 
// Function to find the number of factors
void findFactors(int a, int b)
{
    int c;
    c = a + b - 1;
 
    // print the number of factors
    cout << c;
}
 
// Driver code
int main()
{
    // initialize the factors position
    int a, b;
    a = 13;
    b = 36;
 
    findFactors(a, b);
 
    return 0;
}

Java

// Java program to implement
// the above problem
class GFG
{
 
// Function to find the number of factors
static void findFactors(int a, int b)
{
    int c;
    c = a + b - 1;
 
    // print the number of factors
    System.out.print(c);
}
 
// Driver code
public static void main(String[] args)
{
    // initialize the factors position
    int a, b;
    a = 13;
    b = 36;
 
    findFactors(a, b);
}
}
 
// This code is contributed by Princi Singh

Python3

# Python 3 program to implement
# the above problem
 
# Function to find the number of factors
def findFactors(a, b):
    c = a + b - 1
 
    # print the number of factors
    print(c)
 
# Driver code
if __name__ == '__main__':
     
    # initialize the factors position
    a = 13
    b = 36
    findFactors(a, b)
     
# This code is contributed by
# Surendra_Gangwar

C#

// C# program to implement
// the above problem
using System;
     
class GFG
{
 
// Function to find the number of factors
static void findFactors(int a, int b)
{
    int c;
    c = a + b - 1;
 
    // print the number of factors
    Console.Write(c);
}
 
// Driver code
public static void Main(String[] args)
{
    // initialize the factors position
    int a, b;
    a = 13;
    b = 36;
 
    findFactors(a, b);
}
}
 
// This code is contributed by PrinciRaj1992

Javascript

<script>
 
// Javascript program to implement
// the above problem
 
// Function to find the number of factors
function findFactors(a, b)
{
    let c;
    c = a + b - 1;
 
    // print the number of factors
    document.write(c);
}
 
// Driver code
 
// initialize the factors position
let a, b;
a = 13;
b = 36;
 
findFactors(a, b);
 
</script>
Producción: 

48

 

Complejidad de tiempo : O(1)
 

Publicación traducida automáticamente

Artículo escrito por AmanSrivastava1 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 *