1# -*- coding: utf-8 -*-2# Copyright 2011 Takeshi KOMIYA3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.1516from __future__ import division171819def gcd(*args):20 if len(args) == 0:21 return 022 elif len(args) == 1:23 return args[0]24 elif len(args) == 2:25 if args[1] == 0:26 return args[0]27 else:28 return gcd(args[1], args[0] % args[1])29 else:30 return gcd(gcd(*args[:-1]), args[-1])313233def lcm(*args):34 if len(args) == 0:35 return 036 elif len(args) == 1:37 return args[0]38 elif len(args) == 2:39 return args[0] * args[1] // gcd(*args)40 else:41 return lcm(lcm(*args[:-1]), args[-1])