Teorema de Hardy-Ramanujan

El teorema de Hardy Ramanujam establece que el número de factores primos de n será aproximadamente log(log(n)) para la mayoría de los números naturales n
Ejemplos: 
 

5192 tiene 2 factores primos distintos y log(log(5192)) = 2,1615 
51242183 tiene 3 factores primos distintos y log(log(51242183)) = 2,8765

Como cita la declaración, es solo una aproximación. Hay contraejemplos como 
 

510510 tiene 7 factores primos distintos pero log(log(510510)) = 2.5759 
1048576 tiene 1 factor primo pero log(log(1048576)) = 2.62922

Este teorema se usa principalmente en algoritmos de aproximación y su demostración conduce a conceptos más amplios en la teoría de la probabilidad. 
 

C++

// CPP program to count all prime factors
#include <bits/stdc++.h>
using namespace std;
 
// A function to count prime factors of
// a given number n
int exactPrimeFactorCount(int n)
{
    int count = 0;
 
    if (n % 2 == 0) {
        count++;
        while (n % 2 == 0)
            n = n / 2;
    }
 
    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        if (n % i == 0) {
            count++;
            while (n % i == 0)
                n = n / i;
        }
    }
 
    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        count++;
    return count;
}
 
// driver function
int main()
{
    int n = 51242183;
    cout << "The number of distinct prime factors is/are "
         << exactPrimeFactorCount(n) << endl;
    cout << "The value of log(log(n)) is "
         << log(log(n)) << endl;
    return 0;
}

Java

// Java program to count all prime factors
import java.io.*;
 
class GFG {
     
    // A function to count prime factors of
    // a given number n
    static int exactPrimeFactorCount(int n)
    {
        int count = 0;
     
        if (n % 2 == 0) {
            count++;
            while (n % 2 == 0)
                n = n / 2;
        }
     
        // n must be odd at this point. So we can skip
        // one element (Note i = i +2)
        for (int i = 3; i <= Math.sqrt(n); i = i + 2)
        {
            if (n % i == 0) {
                count++;
                while (n % i == 0)
                    n = n / i;
            }
        }
     
        // This condition is to handle the case
        // when n is a prime number greater than 2
        if (n > 2)
            count++;
        return count;
    }
     
    // driver function
    public static void main (String[] args)
    {
        int n = 51242183;
        System.out.println( "The number of distinct "
                            + "prime factors is/are "
            + exactPrimeFactorCount(n));
        System.out.println( "The value of log(log(n))"
                   + " is " + Math.log(Math.log(n))) ;
    }
}
 
// This code is contributed by anuj_67.

Python3

# Python3 program to count all
# prime factors
import math
 
# A function to count
# prime factors of
# a given number n
def exactPrimeFactorCount(n) :
    count = 0
    if (n % 2 == 0) :
        count = count + 1
        while (n % 2 == 0) :
            n = int(n / 2)
 
    # n must be odd at this
    # point. So we can skip
    # one element (Note i = i +2)
    i = 3
     
    while (i <= int(math.sqrt(n))) :
        if (n % i == 0) :    
            count = count + 1
            while (n % i == 0) :
                n = int(n / i)
        i = i + 2
 
    # This condition is to
    # handle the case when n
    # is a prime number greater
    # than 2
    if (n > 2) :
        count = count + 1
    return count
 
# Driver Code
n = 51242183
print ("The number of distinct prime factors is/are {}".
       format(exactPrimeFactorCount(n), end = "\n"))
print ("The value of log(log(n)) is {0:.4f}"
            .format(math.log(math.log(n))))
 
# This code is contributed by Manish Shaw
# (manishshaw1)

C#

// C# program to count all prime factors
using System;
 
class GFG {
     
    // A function to count prime factors of
    // a given number n
    static int exactPrimeFactorCount(int n)
    {
        int count = 0;
     
        if (n % 2 == 0) {
            count++;
            while (n % 2 == 0)
                n = n / 2;
        }
     
        // n must be odd at this point. So
        // we can skip one element
        // (Note i = i +2)
        for (int i = 3; i <= Math.Sqrt(n);
                                 i = i + 2)
        {
            if (n % i == 0) {
                count++;
                while (n % i == 0)
                    n = n / i;
            }
        }
     
        // This condition is to handle the
        // case when n is a prime number
        // greater than 2
        if (n > 2)
            count++;
             
        return count;
    }
     
    // Driver function
    public static void Main ()
    {
        int n = 51242183;
         
        Console.WriteLine( "The number of"
        + " distinct prime factors is/are "
              + exactPrimeFactorCount(n));
               
        Console.WriteLine( "The value of "
                       + "log(log(n)) is "
                + Math.Log(Math.Log(n))) ;
    }
}
 
// This code is contributed by anuj_67.

PHP

<?php
// PHP program to count all prime factors
 
// A function to count
// prime factors of
// a given number n
function exactPrimeFactorCount($n)
{
    $count = 0;
 
    if ($n % 2 == 0)
    {
        $count++;
        while ($n % 2 == 0)
            $n = $n / 2;
    }
 
    // n must be odd at this
    // point. So we can skip
    // one element (Note i = i +2)
    for($i = 3; $i <= sqrt($n); $i = $i + 2)
    {
        if ($n % $i == 0)
        {
            $count++;
            while ($n % $i == 0)
                $n = $n / $i;
        }
    }
 
    // This condition is to
    // handle the case when n
    // is a prime number greater
    // than 2
    if ($n > 2)
        $count++;
    return $count;
}
 
    // Driver Code
    $n = 51242183;
    echo "The number of distinct prime".
         " factors is/are ",exactPrimeFactorCount($n),"\n";
          
    echo "The value of log(log(n)) ".
         "is ",log(log($n)),"\n";
 
// This code is contributed by m_kit
?>

Javascript

<script>
// Javascript program to count all prime factors
 
// A function to count
// prime factors of
// a given number n
function exactPrimeFactorCount(n)
{
    let count = 0;
 
    if (n % 2 == 0)
    {
        count++;
        while (n % 2 == 0)
            n = n / 2;
    }
 
    // n must be odd at this
    // point. So we can skip
    // one element (Note i = i +2)
    for(let i = 3; i <= Math.sqrt(n); i = i + 2)
    {
        if (n % i == 0)
        {
            count++;
            while (n % i == 0)
                n = n / i;
        }
    }
 
    // This condition is to
    // handle the case when n
    // is a prime number greater
    // than 2
    if (n > 2)
        count++;
    return count;
}
 
    // Driver Code
    let n = 51242183;
    document.write("The number of distinct prime factors is/are " +
                   exactPrimeFactorCount(n) + "<br>");
         
    document.write("The value of log(log(n)) is "+ Math.log(Math.log(n)) + "<br>");
 
// This code is contributed by _saurabh_jaiswal
</script>
Producción: 

The number of distinct prime factors is/are 3
The value of log(log(n)) is 2.8765

 

Publicación traducida automáticamente

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