結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー kou6839kou6839
提出日時 2015-12-14 12:28:26
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,252 bytes
コンパイル時間 3,156 ms
コンパイル使用メモリ 74,072 KB
実行使用メモリ 66,536 KB
最終ジャッジ日時 2023-10-13 16:28:15
合計ジャッジ時間 24,159 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
56,040 KB
testcase_01 AC 123 ms
55,772 KB
testcase_02 AC 126 ms
55,808 KB
testcase_03 AC 127 ms
55,696 KB
testcase_04 AC 127 ms
55,884 KB
testcase_05 AC 130 ms
56,012 KB
testcase_06 AC 129 ms
55,944 KB
testcase_07 AC 128 ms
55,664 KB
testcase_08 AC 129 ms
55,460 KB
testcase_09 WA -
testcase_10 AC 128 ms
55,888 KB
testcase_11 WA -
testcase_12 AC 127 ms
56,040 KB
testcase_13 AC 129 ms
55,776 KB
testcase_14 AC 598 ms
62,252 KB
testcase_15 AC 769 ms
64,936 KB
testcase_16 AC 530 ms
60,508 KB
testcase_17 AC 168 ms
55,852 KB
testcase_18 WA -
testcase_19 AC 637 ms
62,568 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 414 ms
60,292 KB
testcase_23 AC 709 ms
66,536 KB
testcase_24 WA -
testcase_25 AC 592 ms
61,784 KB
testcase_26 WA -
testcase_27 AC 685 ms
63,380 KB
testcase_28 WA -
testcase_29 AC 806 ms
64,740 KB
testcase_30 AC 218 ms
58,948 KB
testcase_31 WA -
testcase_32 AC 596 ms
60,664 KB
testcase_33 AC 582 ms
59,304 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
権限があれば一括ダウンロードができます

ソースコード

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);
	}
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		long p = sc.nextLong();
		long q = sc.nextLong();
		int n = sc.nextInt();
		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();
		}
		if(gcd(p, q)==1 && (p%2==0 || q%2==0)){
			System.out.println(n);
		}else if(gcd(p, q)==1){
			int ans = 0;
			for(int i=0;i<n;i++){
				if( Math.abs(x[i]-y[i])%2!=0) ans++;
			}
			System.out.println(ans);
		}else if(p==0&&q==0){
			int ans = 0;
			for(int i=0;i<n;i++){
				if( x[i]==0&&y[i]==0) ans++;
			}
			System.out.println(ans);
		}else if(p==0){
			int ans = 0;
			for(int i=0;i<n;i++){
				if( y[i]%q==0 && x[i]%q==0) ans++;
			}
			System.out.println(ans);
		}else if(q==0){
			int ans = 0;
			for(int i=0;i<n;i++){
				if( y[i]%p==0 && x[i]%p==0) ans++;
			}
			System.out.println(ans);
		}else{
			int ans =0;
			long sa = gcd(p, q);
			for(int i=0;i<n;i++){
				if( (x[i]%sa==0 || y[i]%sa==0) && Math.abs(x[i]-y[i])%(sa*2)==0) ans++;
			}
			System.out.println(ans);
		}
	} 
}
0