最后$f(p^x,p^y)$为求x,y的最大公约数,但返回的结果为p^gcd(x,y)
辗转相除法 o(logn) (a,b) = (b,a%b)
辗转相减法 o(n) (a,b) = (b,a-b)
https://blog.csdn.net/destiny_balabala/article/details/105074056
两个指数相减可以转化为相除
两个指数相除开根号
IA = lambda:map(int,input().split())
x = list(IA())
n = x[0]
if len(x)>1:
a = x[1:]
else:
a = list(IA())
res = [[0,0] for i in range(len(a)-1)]
a = list(set(a))
a = sorted(a)
def gcd(a, b):
if b != 0:
return gcd(b, a%b)
return a
def gcd_sub(a, b):
if a < b:a,b = b,a
if b==1:
return a
return gcd_sub(b, a//b)
for i in range(1,len(a)):
temp = gcd(a[i],a[0])
res[i-1][0] = a[i] // temp
res[i-1][1] = a[0] // temp
up = res[0][0]
down = res[0][1]
for i in range(1, len(a)-1):
up = gcd_sub(up, res[i][0])
down = gcd_sub(down,res[i][1])
print(str(up)+"/"+str(down))
我问一句左上角的是啥?
应该是一个谷歌的一个插件
diigo插件, 可以选定文字进行高亮