您的位置:首页 > 其它

[大数GCD Stein算法] BZOJ 1876 [SDOI2009]SuperGCD

2016-07-16 17:44 387 查看
懒得写高精

python水过

<span style="font-family:Microsoft YaHei;font-size:14px;color:#330099;">a=(int)(input())
b=(int)(input())
while b!=0:
t=a
a=b
b=t%b
print a </span>

Stein 算法 

只有减法和位移

<span style="font-family:Microsoft YaHei;font-size:14px;color:#330099;">a=(int)(input())
b=(int)(input())
c=0
while (a!=0 and b!=0):
x=a&1;y=b&1
if (x==0 and y==0):
a>>=1;b>>=1;c=c+1
elif (x==0):
a>>=1
elif (y==0):
b>>=1
elif (a>b):
a-=b
else:
b-=a;
while (c!=0):
a<<=1;c=c-1
print a

</span>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: