結果
問題 |
No.280 歯車の問題(1)
|
ユーザー |
|
提出日時 | 2015-09-19 13:22:20 |
言語 | Python2 (2.7.18) |
結果 |
AC
|
実行時間 | 24 ms / 1,000 ms |
コード長 | 1,469 bytes |
コンパイル時間 | 48 ms |
コンパイル使用メモリ | 6,912 KB |
実行使用メモリ | 8,064 KB |
最終ジャッジ日時 | 2024-07-19 07:54:20 |
合計ジャッジ時間 | 3,521 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
ソースコード
#!/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()))))