結果
| 問題 | No.858 わり算 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-03-01 06:01:29 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 6,132 bytes |
| 記録 | |
| コンパイル時間 | 158 ms |
| コンパイル使用メモリ | 82,424 KB |
| 実行使用メモリ | 55,420 KB |
| 最終ジャッジ日時 | 2024-10-03 00:45:53 |
| 合計ジャッジ時間 | 1,042 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 1 |
| other | AC * 2 WA * 5 |
ソースコード
def digit_shift(S, l):
if '.' in S:
a, b = S.split('.')
n = int(a + b) * 10 ** (l - len(b))
else:
n = int(S) * 10 ** l
return n
def digit_shift_inv(N,l,digit):
"""
10^-l 掛けた物を 有効数字=digit で返す
"""
S=str(N)
L=len(S)
if l==0: return S
elif L<=l:
f="0"*(l-L)+S
if len(f)>=digit: return "0."+f[:digit]
else: return "0."+f+"0"*(digit-l)
else:
f=S[-l:]
if len(f)>=digit: return S[:-l]+"."+f[:digit]
else: return S[:-l]+"."+"0"*(digit-l)
def is_square(N):
"""
N = a**2 + r
If r==0, N is squared number.
"""
a,r = 0,0
for s in reversed(range(0,N.bit_length(),2)):
t = N>>s&3
r = r<<2|t
c = a<<2|1
b = r>=c
if b: r -= c
a = a<<1|b
return (a,r)
class Digit:
def __init__(self,x,precision=-1):
"""
:param precision: 内部計算の有効小数点以下桁数
"""
if precision==-1:
self.l=default_precision
else:
self.l=precision
self.M=10**self.l
if type(x)==int:
self.x=x*self.M
else:
self.x=digit_shift(x,self.l)
def __eq__(self, other):
if isinstance(other, Digit):
return self.x==other.x
else:
return self.x==other*self.M
def __ne__(self, other):
if isinstance(other, Digit):
return self.x!=other.x
else:
return self.x!=other*self.M
def __lt__(self, other):
if isinstance(other, Digit):
return self.x<other.x
else:
return self.x<other*self.M
def __le__(self, other):
if isinstance(other, Digit):
return self.x<=other.x
else:
return self.x<=other*self.M
def __gt__(self,other):
if isinstance(other, Digit):
return self.x>other.x
else:
return self.x>other*self.M
def __ge__(self,other):
if isinstance(other, Digit):
return self.x>=other.x
else:
return self.x>=other*self.M
def __neg__(self):
res=Digit(0,self.l)
res.x=-self.x
return res
def __sub__(self, other):
res=Digit(0,self.l)
if isinstance(other, Digit):
res.x=self.x-other.x
else:
res.x=self.x-other*self.M
return res
def __rsub__(self, other):
res=Digit(0,self.l)
if isinstance(other, Digit):
res.x=other.x-self.x
else:
res.x=other*self.M-self.x
return res
def __add__(self, other):
res=Digit(0,self.l)
if isinstance(other, Digit):
res.x=self.x+other.x
else:
res.x=self.x+other*self.M
return res
def __radd__(self, other):
res=Digit(0,self.l)
if isinstance(other, Digit):
res.x=other.x+self.x
else:
res.x=other*self.M+self.x
return res
def __mul__(self, other):
res=Digit(0,self.l)
if isinstance(other, Digit):
res.x=self.x*other.x//self.M
else:
res.x=self.x*other
return res
def __rmul__(self, other):
res=Digit(0,self.l)
if isinstance(other, Digit):
res.x=other.x*self.x//self.M
else:
res.x=other*self.x
return res
def __truediv__(self, other):
res=Digit(0,self.l)
if isinstance(other, Digit):
res.x=self.x*self.M//other.x
else:
res.x=self.x//other
return res
def __rtruediv__(self, other):
res=Digit(0,self.l)
if isinstance(other, Digit):
res.x=other.x*self.M//self.x
else:
res.x=other*self.M*self.M//self.x
return res
def __pow__(self,power):
res=Digit(0,self.l)
p=self.M
m=self.x
while power>0:
if power&1:
p*=m
p//=self.M
m*=m
m//=self.M
power>>=1
res.x=p
return res
def __iadd__(self, other):
if isinstance(other, Digit):
self.x+=other.x
else:
self.x+=other*self.M
return self
def __isub__(self, other):
if isinstance(other, Digit):
self.x-=other.x
else:
self.x-=other*self.M
return self
def __imul__(self, other):
if isinstance(other, Digit):
self.x*=other.x
self.x//=self.M
else:
self.x*=other
return self
def __itruediv__(self, other):
if isinstance(other, Digit):
self.x*=self.M
self.x//=other.x
else:
self.x//=other
return self
def __abs__(self):
res=Digit(0,self.l)
res.x=abs(self.x)
return res
def __hash__(self):
return self.x
def __int__(self):
return self.x//self.M
def __str__(self):
return digit_shift_inv(self.x,self.l,self.l)
def __format__(self, spec):
""" "{:6}".format(self) = 小数点以下6桁 """
if spec:
return digit_shift_inv(self.x,self.l,int(spec))
else: digit_shift_inv(self.x,self.l,self.l)
def __floor__(self):
return self.x//self.M
def __ceil__(self):
return (self.x-1)//self.M+1
def sqrt(self):
res=Digit(0,self.l)
a,r=is_square(self.x*self.M)
res.x=a
return res
def is_integer(self):
return self.x%self.M==0
###############################################
def example():
global input
example = iter(
"""
3.1 2
"""
.strip().split("\n"))
input = lambda: next(example)
###############################################
import sys
input = sys.stdin.readline
from math import floor,ceil
# example()
default_precision=100 # デフォルト小数点以下桁数は 10
X,Y=map(Digit, input().split())
print("{:50}".format(X*Y))