結果

問題 No.280 歯車の問題(1)
コンテスト
ユーザー yuppe19 😺
提出日時 2015-09-19 13:22:20
言語 Python2
(2.7.18)
結果
AC  
実行時間 29 ms / 1,000 ms
コード長 1,469 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 72 ms
コンパイル使用メモリ 7,848 KB
最終ジャッジ日時 2025-12-03 17:07:01
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#!/usr/bin/python
from operator import mul
from fractions import Fraction
from itertools import izip, tee

class MyFraction(Fraction):
    from operator import add, sub, mul, div
    def __add__(self, other):  return MyFraction(reduce(add, map(Fraction, (self, other))))
    def __radd__(self, other): return MyFraction(reduce(add, map(Fraction, (other, self))))
    def __sub__(self, other):  return MyFraction(reduce(sub, map(Fraction, (self, other))))
    def __rsub__(self, other): return MyFraction(reduce(sub, map(Fraction, (other, self))))
    def __mul__(self, other):  return MyFraction(reduce(mul, map(Fraction, (self, other))))
    def __rmul__(self, other): return MyFraction(reduce(mul, map(Fraction, (other, self))))
    def __div__(self, other):  return MyFraction(reduce(div, map(Fraction, (self, other))))
    def __rdiv__(self, other): return MyFraction(reduce(div, map(Fraction, (other, self))))
    def __pow__(self, other):  return MyFraction(reduce(pow, map(Fraction, (self, other))))
    def __rpow__(self, other): return MyFraction(reduce(pow, map(Fraction, (other, self))))
    def __str__(self): return '{}/{}'.format(self.numerator, self.denominator)
    def __repr__(self): return 'MyFraction {}/{}'.format(self.numerator, self.denominator)

def pairwise(iterable):
    a, b = tee(iterable)
    next(b, None)
    return izip(a, b)

raw_input()
print reduce(mul, map(lambda (x, y): MyFraction(y, x), pairwise(map(int, raw_input().split()))))
0