結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー kou6839kou6839
提出日時 2015-12-16 15:33:26
言語 Java21
(openjdk 21)
結果
AC  
実行時間 768 ms / 2,000 ms
コード長 955 bytes
コンパイル時間 4,111 ms
コンパイル使用メモリ 73,836 KB
実行使用メモリ 50,516 KB
最終ジャッジ日時 2023-09-21 03:27:24
合計ジャッジ時間 23,222 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
38,988 KB
testcase_01 AC 114 ms
38,960 KB
testcase_02 AC 113 ms
38,896 KB
testcase_03 AC 116 ms
39,064 KB
testcase_04 AC 116 ms
39,672 KB
testcase_05 AC 120 ms
39,124 KB
testcase_06 AC 122 ms
39,404 KB
testcase_07 AC 121 ms
38,932 KB
testcase_08 AC 119 ms
38,880 KB
testcase_09 AC 120 ms
38,960 KB
testcase_10 AC 121 ms
38,872 KB
testcase_11 AC 121 ms
39,408 KB
testcase_12 AC 121 ms
39,184 KB
testcase_13 AC 123 ms
39,224 KB
testcase_14 AC 601 ms
47,432 KB
testcase_15 AC 747 ms
50,516 KB
testcase_16 AC 520 ms
45,528 KB
testcase_17 AC 165 ms
39,680 KB
testcase_18 AC 559 ms
45,740 KB
testcase_19 AC 615 ms
47,776 KB
testcase_20 AC 733 ms
49,368 KB
testcase_21 AC 629 ms
47,196 KB
testcase_22 AC 409 ms
45,284 KB
testcase_23 AC 677 ms
49,952 KB
testcase_24 AC 436 ms
45,448 KB
testcase_25 AC 610 ms
46,856 KB
testcase_26 AC 751 ms
50,144 KB
testcase_27 AC 680 ms
48,936 KB
testcase_28 AC 666 ms
49,116 KB
testcase_29 AC 768 ms
50,508 KB
testcase_30 AC 210 ms
43,584 KB
testcase_31 AC 186 ms
40,588 KB
testcase_32 AC 588 ms
46,068 KB
testcase_33 AC 554 ms
45,644 KB
testcase_34 AC 506 ms
45,548 KB
testcase_35 AC 670 ms
50,280 KB
testcase_36 AC 220 ms
43,352 KB
testcase_37 AC 621 ms
47,180 KB
testcase_38 AC 577 ms
45,740 KB
testcase_39 AC 383 ms
45,496 KB
testcase_40 AC 700 ms
49,268 KB
testcase_41 AC 463 ms
45,420 KB
testcase_42 AC 663 ms
49,976 KB
testcase_43 AC 512 ms
45,984 KB
testcase_44 AC 686 ms
49,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	static long gcd(long a,long b){
		return b == 0 ? a : gcd(b, a%b);
	}
	static long lcm(long a, long b){
		return a*b/gcd(a, b);
	}
	static int[] dx = {1,0,-1,0};
	static int[] dy = {0,1,0,-1};
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		long p = sc.nextLong();
		long q = sc.nextLong();
		int n = sc.nextInt();
		if(p>q){
			long tmp = p;
			p = q;
			q = tmp;
		}
		int[] x = new int[n];
		int[] y = new int[n];
		for(int i=0;i<n;i++){
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}
		int ret = 0;
		if(q>0){
			long g = gcd(p, q);
			if(((p/g)+(q/g))%2==1){
				for(int i=0;i<n;i++){
					if(x[i]%g==0 && y[i]%g==0) ret++;
				}
			}else{
				for(int i=0;i<n;i++){
					if(x[i]%g==0 && y[i]%g==0 && Math.abs(x[i]/g+y[i]/g)%2==0){
						ret++;
					}
				}
			}
		}else{
			for(int i=0;i<n;i++) if(x[i]==0 && y[i]==0) ret++;
		}
		System.out.println(ret);
	}
}
0