Exemplo n.º 1
0
def isAchillesNumber( n ):
    factors = getECMFactors( n ) if g.ecm else getFactors( n )

    if min( [ i[ 1 ] for i in factors ] ) < 2:
        return 0

    return 1 if getGCD( [ i[ 1 ] for i in factors ] ) == 1 else 0
Exemplo n.º 2
0
def getSigma( target ):
    '''
    Returns the sum of the divisors of n, including 1 and n.

    http://math.stackexchange.com/questions/22721/is-there-a-formula-to-calculate-the-sum-of-all-proper-divisors-of-a-number
    '''
    n = floor( target )

    if real( n ) == 0:
        return 0
    elif n == 1:
        return 1

    factors = getECMFactors( n ) if g.ecm else getFactors( n )

    result = 1

    for factor in factors:
        numerator = fsub( power( factor[ 0 ], fadd( factor[ 1 ], 1 ) ), 1 )
        denominator = fsub( factor[ 0 ], 1 )
        #debugPrint( 'sigma', numerator, denominator )
        result = fmul( result, fdiv( numerator, denominator ) )

        if result != floor( result ):
            raise ValueError( 'insufficient precision for \'sigma\', increase precision (-p))' )

    return result
Exemplo n.º 3
0
def isUnusual( n ):
    if real_int( n ) < 2:
        return 0

    factors = getECMFactors( n ) if g.ecm else getFactors( n )

    return 1 if max( [ i[ 0 ] for i in factors ] ) > sqrt( n ) else 0
Exemplo n.º 4
0
def isSquareFree( n ):
    if real_int( n ) == 0:
        return 0

    factors = getECMFactors( n ) if g.ecm else getFactors( n )

    return 1 if max( [ i[ 1 ] for i in factors ] ) == 1 else 0
Exemplo n.º 5
0
def isSphenic( n ):
    factors = getECMFactors( n ) if g.ecm else getFactors( n )

    if len( factors ) != 3:
        return 0

    return 1 if max( [ i[ 1 ] for i in factors ] ) == 1 else 0
Exemplo n.º 6
0
def isRough( n, k ):
    if real( n ) < real( k ):
        return 0

    factors = getECMFactors( n ) if g.ecm else getFactors( n )

    return 1 if min( [ i[ 0 ] for i in factors ] ) >= k else 0
Exemplo n.º 7
0
def isSmooth( n, k ):
    if real( n ) < real( k ):
        return 0

    factors = getECMFactors( n ) if g.ecm else getFactors( n )

    return 1 if max( [ i[ 0 ] for i in factors ] ) <= k else 0
Exemplo n.º 8
0
def getDivisors( n ):
    if n == 0:
        return [ 0 ]
    elif n == 1:
        return [ 1 ]

    factors = getECMFactors( n ) if g.ecm else getFactors( n )

    return sorted( createDivisorList( [ ], factors ) )
Exemplo n.º 9
0
def getMobius( n ):
    if real( n ) == 1:
        return 1

    factors = getECMFactors( n ) if g.ecm else getFactors( n )

    for i in factors:
        if i[ 1 ] > 1:
            return 0

    if len( factors ) % 2:
        return -1
    else:
        return 1
Exemplo n.º 10
0
def getSigmaN( n, k ):
    '''
    Returns the sum of the divisors of n, including 1 and n, to the k power.

    https://oeis.org/A001157
    '''
    if real( n ) == 0:
        return 0
    elif n == 1:
        return 1

    factors = getECMFactors( n ) if g.ecm else getFactors( n )

    result = 1

    for factor in factors:
        numerator = fsub( power( factor[ 0 ], fmul( fadd( factor[ 1 ], 1 ), k ) ), 1 )
        denominator = fsub( power( factor[ 0 ], k ), 1 )
        result = fmul( result, fdiv( numerator, denominator ) )

        if result != floor( result ):
            raise ValueError( 'insufficient precision for \'sigma_n\', increase precision (-p))' )

    return result
Exemplo n.º 11
0
def getEulerPhi( n ):
    if real( n ) < 2:
        return n

    if g.ecm:
        return reduce( fmul, ( fmul( fsub( i[ 0 ], 1 ), power( i[ 0 ], fsub( i[ 1 ], 1 ) ) ) for i in getECMFactors( n ) ) )
    else:
        return reduce( fmul, ( fmul( fsub( i[ 0 ], 1 ), power( i[ 0 ], fsub( i[ 1 ], 1 ) ) ) for i in getFactors( n ) ) )
Exemplo n.º 12
0
def getDivisorCount( n ):
    if n == 1:
        return 1

    factors = getECMFactors( n ) if g.ecm else getFactors( n )
    return fprod( [ i[ 1 ] + 1 for i in factors ] )
Exemplo n.º 13
0
def isPowerful( n ):
    factors = getECMFactors( n ) if g.ecm else getFactors( n )

    return 1 if min( [ i[ 1 ] for i in factors ] ) >= 2 else 0
Exemplo n.º 14
0
def isKSemiPrime( n, k ):
    factors = getECMFactors( n ) if g.ecm else getFactors( n )

    return 1 if sum( [ i[ 1 ] for i in factors ] ) == k else 0