結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー 👑 KazunKazun
提出日時 2020-08-19 02:09:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 161 ms / 2,000 ms
コード長 3,875 bytes
コンパイル時間 214 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 86,500 KB
最終ジャッジ日時 2024-04-20 08:06:48
合計ジャッジ時間 6,703 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,992 KB
testcase_01 AC 36 ms
53,248 KB
testcase_02 AC 34 ms
52,992 KB
testcase_03 AC 37 ms
52,736 KB
testcase_04 AC 32 ms
52,992 KB
testcase_05 AC 32 ms
53,376 KB
testcase_06 AC 35 ms
52,992 KB
testcase_07 AC 33 ms
52,992 KB
testcase_08 AC 36 ms
52,736 KB
testcase_09 AC 35 ms
52,992 KB
testcase_10 AC 35 ms
52,864 KB
testcase_11 AC 34 ms
52,736 KB
testcase_12 AC 34 ms
52,992 KB
testcase_13 AC 34 ms
53,168 KB
testcase_14 AC 127 ms
83,436 KB
testcase_15 AC 135 ms
85,756 KB
testcase_16 AC 112 ms
81,100 KB
testcase_17 AC 41 ms
60,472 KB
testcase_18 AC 126 ms
81,328 KB
testcase_19 AC 131 ms
83,104 KB
testcase_20 AC 152 ms
86,500 KB
testcase_21 AC 121 ms
82,096 KB
testcase_22 AC 108 ms
77,976 KB
testcase_23 AC 133 ms
82,868 KB
testcase_24 AC 110 ms
78,720 KB
testcase_25 AC 115 ms
82,196 KB
testcase_26 AC 152 ms
85,596 KB
testcase_27 AC 136 ms
83,792 KB
testcase_28 AC 147 ms
83,524 KB
testcase_29 AC 138 ms
85,548 KB
testcase_30 AC 76 ms
76,652 KB
testcase_31 AC 51 ms
67,072 KB
testcase_32 AC 102 ms
80,256 KB
testcase_33 AC 121 ms
81,772 KB
testcase_34 AC 120 ms
80,512 KB
testcase_35 AC 131 ms
82,808 KB
testcase_36 AC 80 ms
76,544 KB
testcase_37 AC 134 ms
82,952 KB
testcase_38 AC 121 ms
81,664 KB
testcase_39 AC 91 ms
77,612 KB
testcase_40 AC 161 ms
85,956 KB
testcase_41 AC 101 ms
78,888 KB
testcase_42 AC 142 ms
84,316 KB
testcase_43 AC 121 ms
80,896 KB
testcase_44 AC 136 ms
83,732 KB
権限があれば一括ダウンロードができます

ソースコード

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)
0