• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python sympy.factorint函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sympy.factorint函数的典型用法代码示例。如果您正苦于以下问题:Python factorint函数的具体用法?Python factorint怎么用?Python factorint使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了factorint函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: least_common_multiple

def least_common_multiple(divisors=range(1, 21)):
    # Returns least common multiple of INTs in <divisors>

    # No matter the divisors, we at least need the max divisor as an LCM
    lcm = max(divisors)
    lcm_factors = sympy.factorint(lcm)

    for n in divisors:
        n_factors = sympy.factorint(n)

        for f in n_factors:

            # If this factor appears in the LCM ...
            if f in lcm_factors:
                factor_excess = lcm_factors[f] - n_factors[f]

                # ... check if there are enough of them
                if factor_excess < 0:

                    # If not, we multiply into LCM to account for this
                    lcm *= - factor_excess * f
                    lcm_factors[f] += - factor_excess

            # If this factor does not appear in the LCM, multiple into LCM
            else:
                lcm *= n_factors[f] * f
                lcm_factors[f] = n_factors[f]

    return lcm
开发者ID:jnfrye,项目名称:euler,代码行数:29,代码来源:integers.py


示例2: main

def main():
        print "euler23.py"
        print sum(proper_factors(28))
        print deficient(28)
        print perfect(28)
        print factorint(28)
        abridged_abundant = lambda(x): x%6 != 0 and x%28 != 0 and x%496 != 0 and abundant(x)
        print ascuii_map([('X', abridged_abundant), (' ', nil)], ['list', 0, 8000, 60])
开发者ID:cutecprog,项目名称:playcode,代码行数:8,代码来源:euler23.py


示例3: main

def main():
    count = 0
    min = 2 * 3 * 5 * 7
    while True:
        if len(sympy.factorint(min)) == 4:
            count = count + 1
        else:
            count = 0
        if count == 4:
            print ("%d" % (min - 3))
            print(sympy.factorint(min - 3))
            break
        min = min + 1
开发者ID:stauntonknight,项目名称:algorithm,代码行数:13,代码来源:47_1.py


示例4: euler47

def euler47():
    i = 646
    while True:
        i += 1
        if all(len(factorint(i+j).keys()) == 4 for j in range(4)):
            print(i)
            return
开发者ID:mertcanekiz,项目名称:Euler,代码行数:7,代码来源:euler047.py


示例5: is_semiprime

def is_semiprime(n):
    factors = sym.factorint(n)
    if len(factors) == 2:
        return n
    if len(factors.values()) == 1 and list(factors.values())[0] == 2:
        return n
    return 0
开发者ID:renanbirck,项目名称:project-euler-solutions,代码行数:7,代码来源:problem187.py


示例6: primes_pop

def primes_pop(a):
    if isinstance(a, int):
        if a < 2:
            return []
        try:
            import sympy
            factor_dict = sympy.factorint(a)
            factors_with_mult = [[fact for _ in range(factor_dict[fact])] for fact in factor_dict]
            return sorted(sum(factors_with_mult, []))
        except:
            working = a
            output = []
            num = 2
            while num * num <= working:
                while working % num == 0:
                    output.append(num)
                    working //= num
                num += 1
            if working != 1:
                output.append(working)
            return output
    if is_num(a):
        return cmath.phase(a)
    if is_seq(a):
        return a[:-1]
    raise BadTypeCombinationError("P", a)
开发者ID:CrazyPython,项目名称:pyth,代码行数:26,代码来源:macros.py


示例7: factor

def factor(expression, variable = None, ensemble = None, decomposer_entiers = True):
    if isinstance(expression, (int, long, Integer)):
        if decomposer_entiers:
            return ProduitEntiers(*factorint(expression).iteritems())
        else:
            return expression


    elif isinstance(expression, Basic) and expression.is_polynomial():
        if variable is None:
            variable = extract_var(expression)
        if variable is None:
            # polynôme à plusieurs variables
            return factor_(expression)
        else:
            try:
                return poly_factor(expression, variable, ensemble)
            except NotImplementedError:
                if param.debug:
                    print_error()
                return expression
    resultat = together_(expression)
    if resultat.is_rational_function():
        num, den = resultat.as_numer_denom()
        if den != 1:
            return factor(num, variable, ensemble, decomposer_entiers)/factor(den, variable, ensemble, decomposer_entiers)
    else:
        resultat = auto_collect(resultat)
        if resultat.is_Mul:
            produit = 1
            for facteur in resultat.args:
                if facteur != 1:
                    produit *= factor(facteur, variable, ensemble, decomposer_entiers)
            return produit
        return resultat
开发者ID:Grahack,项目名称:geophar,代码行数:35,代码来源:sympy_functions.py


示例8: operate

	def operate(self, a):
		if isinstance(a, int):
			if a < 0:
				# Primality testing
				return len(self.operate(-a)) == 1
			if a < 2:
				return []
			try:
				from sympy import factorint
				factor_dict = factorint(a)
				factors_with_mult = [[fact for _ in range(
					factor_dict[fact])] for fact in factor_dict]
				return sorted(sum(factors_with_mult, []))
			except:
				working = a
				output = []
				num = 2
				while num * num <= working:
					while working % num == 0:
						output.append(num)
						working //= num
					num += 1
				if working != 1:
					output.append(working)
				return output
		if is_num(a):
			return cmath.phase(a)
		if is_seq(a):
			return a[:-1]
		raise BadTypeCombinationError("P", a)
开发者ID:Maltysen,项目名称:pyth_native,代码行数:30,代码来源:nodes.py


示例9: apply

 def apply(self, n, evaluation):
     'FactorInteger[n_]'
     
     if isinstance(n, Integer):
         factors = sympy.factorint(n.value)
         factors = sorted(factors.iteritems())
         return Expression('List', *[Expression('List', factor, exp) for factor, exp in factors])
     elif isinstance(n, Rational):
         factors = sympy.factorint(n.value.numer())
         factors_denom = sympy.factorint(n.value.denom())
         for factor, exp in factors_denom.iteritems():
             factors[factor] = factors.get(factor, 0) - exp
         factors = sorted(factors.iteritems())
         return Expression('List', *[Expression('List', factor, exp) for factor, exp in factors])
     else:
         return evaluation.message('FactorInteger', 'exact', n)
开发者ID:cjiang,项目名称:Mathics,代码行数:16,代码来源:numbertheory.py


示例10: factor

 def factor(self, n):
     """Simple example of specific protocol functionality
     """
     log.msg('Factor ', n)
     f = factorint(long(n))
     log.msg('Factors: ', str(f))
     return 
开发者ID:deldotdr,项目名称:magnet,代码行数:7,代码来源:work_consumer.py


示例11: decodersa

def decodersa(n, e, c):
    
    # using sympy factor int function obtain p,q.
    # takes significant time for long numbers
    primes = factorint(n)
    
    p, _ = dict.popitem(primes)
    q, _ = dict.popitem(primes)

    p1, q1 = p-1, q-1

    # check p-1 and q-1
    if not(gcd(p1 * q1, n) == 1):
        raise Exception('Incorrect p-1 and q-1, their GCD is not 1')
  
    p1q1 = p1 * q1

    # now we solve e*d = 1 (mod (p-1)(q-1))
    # e^-1 (mod (p-1)(q-1))
    e1 = modinv(e, p1q1)

    # check that e1 is e's modular inverse
    if not(pow(e * e1, 1, p1q1) == 1):
        raise Exception('Incorrect e^-1 and e, e*e^-1 not 1')

    # solve for d
    d = e1 % p1q1

    # solve c^d (mod n)
    decoded = pow(long(c), d, n)

    return num2alph(str(decoded))
开发者ID:re-skinnybear,项目名称:NumberTheoryCrypt,代码行数:32,代码来源:finalproject.py


示例12: factor_special

def factor_special(n):
    dic1 = sympy.factorint(n)
    dic2 = {}
    for i in dic1:
        if dic1[i] != 1:
            dic2[i] = dic1[i]//2
    return dic2
开发者ID:oursinblanc,项目名称:Euler,代码行数:7,代码来源:pb251.py


示例13: fac_list

def fac_list(n):
    f_list = [1]
    prime_fac_dict = sympy.factorint(n)
    for i, j in prime_fac_dict.items():
        f_list.extend([a * i ** k for a in f_list[:] for k in range(1, j+1)])
    f_list.remove(n)
    return f_list
开发者ID:noinil,项目名称:euler_pysolution,代码行数:7,代码来源:p021_Amicable_numbers.py


示例14: phi

def phi(n):
    factor = list(factorint(n))
    
    phi = n
    for i in range(1, len(factor) +1):
        for j in combinations(factor, i):
            phi += (-1) ** i * (n // product(j))
    return phi
开发者ID:tak0kada,项目名称:procon,代码行数:8,代码来源:70.py


示例15: omega

def omega(nval):
    if nval == 1:
        return 0
    if nval in prime_exponent_dicts:
        pd = prime_exponent_dicts[nval]
    else:
        pd = sympy.factorint(nval)
        prime_exponent_dicts[nval] = pd
    return len(pd)
开发者ID:jnash67,项目名称:eulerpython,代码行数:9,代码来源:numtheory.py


示例16: phi

def phi(n):
    if isPrime(n):
        return n-1
    else:
        factors = factorint(n)
        res = n
        for f in list(factors.keys()):
            res = res*(1 - 1/f)
    return res
开发者ID:StevenYeu,项目名称:Crypto,代码行数:9,代码来源:crypto.py


示例17: eval

 def eval(cls, expr):
     if expr.is_Integer:
         from sympy import factorint
         factors = factorint(Abs(expr), limit=10000)
         factorlist=list(factors.keys())
         factorlist.sort()
         return factorlist[0]
     else:
         raise ValueError("Argument to smallest_factor must be an integer")
开发者ID:dqnykamp,项目名称:mathinsight,代码行数:9,代码来源:user_commands.py


示例18: main

def main():
    ''' main function '''
    while True:    # input value <= zero to exit
        val = input("input an postive integer (0 to quit): ")
        val = int(val)
        if val <= 0:
            break
        fdict = factorint(val)
        print(fdict)
开发者ID:ericosur,项目名称:ericosur-snippet,代码行数:9,代码来源:pyfactorial.py


示例19: radical

def radical(n):
    """A radical is the product of distinct prime factors

    For example, 504 = 2^3 x 3^2 x 7, so radical(504) = 2 x 3 x 7 = 42

    >>> radical(504)
    42
    """
    return product(sympy.factorint(n).keys())
开发者ID:AndrewWalker,项目名称:project-euler,代码行数:9,代码来源:euler.py


示例20: fun

def fun(n):
    if n == 1:
        return 1
    factor_list = [1]
    for i, j in sp.factorint(n).items():
        for s in factor_list[:]:
            for t in range(1, j + 1):
                factor_list.append(s * i ** t)
    factor_list.remove(n)
    return sum(factor_list)
开发者ID:noinil,项目名称:euler_pysolution,代码行数:10,代码来源:p095_Amicable_chains.py



注:本文中的sympy.factorint函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sympy.fibonacci函数代码示例发布时间:2022-05-27
下一篇:
Python sympy.factorial2函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap