简体   繁体   English

不能在python2.7中使用gcd函数

[英]Can't use gcd function in python2.7

what is wrong here I tried to use gcd function but it give me this error but when I used floor and sqrt functions from math it works without any errors这里出了什么问题我尝试使用 gcd 函数但它给了我这个错误但是当我使用数学中的 floor 和 sqrt 函数时它可以正常工作没有任何错误

import math
from random import *
p=int(input("Enter p value"))
q=int(input("Enter q value"))
n=p*q
z=(p-1)*(q-1)
e=0
'''Select E Value'''
seed(1)
while(True):
    Random_Value=randint(2,n)
    if math.gcd(z,Random_Value)==1:
        e=Random_Value
        break

在此处输入图像描述

You can use the gcd function from fractions :您可以使用fractions中的gcd函数:

import fractions
print fractions.gcd(3, 6)

As khelwood said, the gcd function was added to the math module in Python 3.5 ( doc ).正如 khelwood 所说, gcd函数已添加到 Python 3.5 中的math模块( doc )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM