結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー 👑 Kazun
提出日時 2020-08-19 02:09:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 204 ms / 2,000 ms
コード長 3,875 bytes
コンパイル時間 217 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 85,924 KB
最終ジャッジ日時 2024-10-12 03:27:19
合計ジャッジ時間 8,473 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

class Gaussian_Integer():
#
def __init__(self,Real_part=0,Imaginary_part=0):
self.re=Real_part
self.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 s
def __strmake(self,coefficient,axis):
if coefficient==0:
return self
else:
if self=="":
if axis=="":
self+=str(coefficient)
else:
if coefficient==1:self+=axis
elif coefficient==-1:self+="-"+axis
else:self+=str(coefficient)+axis
else:
if coefficient>0:
if coefficient==1:self+="+"+axis
else:self+="+"+str(coefficient)+axis
else:
if coefficient==-1:self+="-"+axis
else:self+=str(coefficient)+axis
return 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.im
if isinstance(other,Gaussian_Integer):
c,d=other.re,other.im
return 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.im
return Gaussian_Integer(other*a,other*b)
#
def __truediv__(self,other):
pass
def __rtruediv__(self,other):
pass
def __floordiv__(self,other):
if isinstance(other,int):
other=Gaussian_Integer(other,0)
a,b=self.re,self.im
c,d=other.re,other.im
n=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 conjugate(self):
return Gaussian_Integer(self.re,-self.im)
def __abs__(self):
import math
return 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 self
def __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,x
while y!=0:
x,y=y,x%y
return x
#=================================================
P,Q=map(int,input().split())
alpha=Gaussian_Integer(P,Q)
beta=alpha.conjugate()
N=int(input())
X=[0]*N
for i in range(N):
a,b=map(int,input().split())
X[i]=Gaussian_Integer(a,b)
if alpha==0:
print(X.count(alpha))
exit()
gamma=gcd(alpha,beta)
K=0
for x in X:
K+=(x%gamma==0)
print(K)
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0