結果
問題 | No.1274 楽しい格子点 |
ユーザー |
👑 ![]() |
提出日時 | 2020-10-30 22:26:38 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,780 bytes |
コンパイル時間 | 167 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 53,504 KB |
最終ジャッジ日時 | 2024-07-22 01:38:52 |
合計ジャッジ時間 | 3,654 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 1 |
other | AC * 11 WA * 46 |
ソースコード
class Gaussian_Integer():#入力定義def __init__(self,Real_part=0,Imaginary_part=0):self.re=Real_partself.im=Imaginary_part#表示定義def __str__(self):s=""s=Gaussian_Integer.__strmake(s,self.re,"")s=Gaussian_Integer.__strmake(s,self.im,"i")if s=="":return "0"else:return sdef __strmake(self,coefficient,axis):if coefficient==0:return selfelse:if self=="":if axis=="":self+=str(coefficient)else:if coefficient==1:self+=axiselif coefficient==-1:self+="-"+axiselse:self+=str(coefficient)+axiselse:if coefficient>0:if coefficient==1:self+="+"+axiselse:self+="+"+str(coefficient)+axiselse:if coefficient==-1:self+="-"+axiselse:self+=str(coefficient)+axisreturn self#四則演算定義#加法def __add__(self,other):if isinstance(other,Gaussian_Integer):return Gaussian_Integer(self.re+other.re,self.im+other.im)else:return Gaussian_Integer(self.re+other,self.im)def __radd__(self,other):if isinstance(other,int):return Gaussian_Integer(self.re+other,self.im)#減法def __sub__(self,other):return self+(-other)def __rsub__(self,other):if isinstance(other,int):return (-self)+other#乗法def __mul__(self,other):a,b=self.re,self.imif isinstance(other,Gaussian_Integer):c,d=other.re,other.imreturn Gaussian_Integer(a*c-b*d,a*d+b*c)else:return Gaussian_Integer(other*a,other*b)def __rmul__(self,other):if isinstance(other,int):a,b=self.re,self.imreturn Gaussian_Integer(other*a,other*b)#除法def __truediv__(self,other):passdef __rtruediv__(self,other):passdef __floordiv__(self,other):if isinstance(other,int):other=Gaussian_Integer(other,0)a,b=self.re,self.imc,d=other.re,other.imn=other.norm()p=(2*(a*c+b*d)+n)//(2*n)q=(2*(b*c-a*d)+n)//(2*n)return Gaussian_Integer(p,q)def __mod__(self,other):return self-other*(self//other)#比較演算子def __eq__(self,other):if isinstance(other,Gaussian_Integer):return (self.re==other.re) and (self.im==other.im)else:return (self-other)==Gaussian_Integer(0,0)def __bool__(self):return not(self==0)#その他def conjugate(self):return Gaussian_Integer(self.re,-self.im)def __abs__(self):import mathreturn math.sqrt(self.norm())def norm(self):return self.re*self.re+self.im*self.im#実数から複素数に変換def Real_to_Complex(self):pass#正負判定#要約#逆数def __inverse(self):pass#符号def __pos__(self):return selfdef __neg__(self):return Gaussian_Integer(-self.re,-self.im)#最大公約数def gcd(x,y):"""Gauss整数 x,yの最大公約数を求める.x,y:Gauss整数"""if x.norm()<y.norm():x,y=y,xwhile y!=0:x,y=y,x%yreturn x#================================================A,B=map(int,input().split())alpha=Gaussian_Integer(A,B)beta =alpha.conjugate()gamma=gcd(alpha,beta)if alpha==0:print(0.25)assert gamma%1==0print(0.3371877158)