部门和楼层操作员的不同答案

时间:2018-07-01 17:55:40

标签: python python-3.x interpreter floor floor-division

我将一个大整数除以5。该操作提供的答案是正确的。但是,当我使用发言权运算符时,它会将单位位置的数字四舍五入。其余所有数字在两种情况下都相同。有人可以告诉我这里发生了什么吗? 代码:

  1 import sys
  2 
  3 def gcd(a, b):
  4     
  5     if b > a:
  6         a, b = b, a
  7 
  8     if b > 0:
  9         return (gcd(a%b, b))
 10     
 11     return a
 12 
 13 def lcm(a, b):
 14     return (a*(b//gcd(a, b)))    #floor operator
 15     
 16 def lcm2(a, b):
 17     return (a*(b/gcd(a, b)))    #division operator
 18 
 19 a, b = 226553150, 1023473145
 20 print (int(lcm(a, b)))
 21 print (int(lcm2(a, b)))

user@ubuntu:~/py$ python3 findlcm.py
46374212988031350
46374212988031352

0 个答案:

没有答案
相关问题