結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー cielciel
提出日時 2015-12-14 04:32:56
言語 Ruby
(3.3.0)
結果
AC  
実行時間 261 ms / 2,000 ms
コード長 575 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 11,628 KB
実行使用メモリ 15,496 KB
最終ジャッジ日時 2023-09-21 03:18:01
合計ジャッジ時間 7,848 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
15,268 KB
testcase_01 AC 82 ms
15,000 KB
testcase_02 AC 83 ms
15,168 KB
testcase_03 AC 78 ms
15,312 KB
testcase_04 AC 77 ms
15,284 KB
testcase_05 AC 78 ms
15,332 KB
testcase_06 AC 78 ms
15,104 KB
testcase_07 AC 79 ms
15,108 KB
testcase_08 AC 79 ms
15,148 KB
testcase_09 AC 78 ms
15,208 KB
testcase_10 AC 78 ms
15,312 KB
testcase_11 AC 78 ms
15,228 KB
testcase_12 AC 80 ms
15,320 KB
testcase_13 AC 78 ms
15,316 KB
testcase_14 AC 156 ms
15,396 KB
testcase_15 AC 197 ms
15,220 KB
testcase_16 AC 123 ms
15,496 KB
testcase_17 AC 78 ms
15,140 KB
testcase_18 AC 135 ms
15,324 KB
testcase_19 AC 154 ms
15,368 KB
testcase_20 AC 194 ms
15,388 KB
testcase_21 AC 159 ms
15,120 KB
testcase_22 AC 98 ms
15,340 KB
testcase_23 AC 195 ms
15,356 KB
testcase_24 AC 105 ms
15,388 KB
testcase_25 AC 143 ms
15,124 KB
testcase_26 AC 191 ms
15,232 KB
testcase_27 AC 163 ms
15,208 KB
testcase_28 AC 163 ms
15,212 KB
testcase_29 AC 224 ms
15,300 KB
testcase_30 AC 83 ms
15,068 KB
testcase_31 AC 80 ms
15,156 KB
testcase_32 AC 155 ms
15,380 KB
testcase_33 AC 141 ms
15,284 KB
testcase_34 AC 133 ms
15,236 KB
testcase_35 AC 261 ms
15,232 KB
testcase_36 AC 83 ms
15,316 KB
testcase_37 AC 170 ms
15,412 KB
testcase_38 AC 153 ms
15,344 KB
testcase_39 AC 114 ms
15,432 KB
testcase_40 AC 218 ms
15,304 KB
testcase_41 AC 138 ms
15,380 KB
testcase_42 AC 183 ms
15,216 KB
testcase_43 AC 136 ms
15,288 KB
testcase_44 AC 175 ms
15,268 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
#coding:utf-8
def egcd(x,y)
	return [x,1,0] if y==0
	g,a,b=egcd(y,x%y)
	[g,b,a-x/y*b]
end

a,b=gets.split.map(&:to_i).sort
if b==0
	gets;p $<.count{|e|
		x,y=e.split.map(&:to_i)
		x==0&&y==0
	}
elsif a==0
	gets;p $<.count{|e|
		x,y=e.split.map(&:to_i)
		x%b==0&&y%b==0
	}
else
	g,z1,z2=egcd(a,b)
	a/=g
	b/=g
	gets;p $<.count{|e|
		x,y=e.split.map{|e|e.to_i}
		next if x%g!=0 || y%g!=0
		x/=g
		y/=g

		#((QQ-PP)n+z2XP+z1XQ-Y)%gcd(2P,2Q)==0
		g0=(2*a).gcd(2*b)
		z=b*b-a*a
		w=z2*x*a+z1*x*b-y
		#zn+w%g0==0
		#zn%g0==-w%g0
		#[-w,z,g0]
		-w%z.gcd(g0)==0
	}
end
0