結果
問題 | No.321 (P,Q)-サンタと街の子供たち |
ユーザー |
![]() |
提出日時 | 2015-12-14 01:37:43 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 773 bytes |
コンパイル時間 | 226 ms |
コンパイル使用メモリ | 23,168 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-06 21:50:30 |
合計ジャッジ時間 | 1,964 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 41 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:11:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 11 | scanf("%d%d%d", &p, &q, &n); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~ main.cpp:14:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 14 | scanf("%d%d", &x[i], &y[i]); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>int p, q, n, x[100000], y[100000];int gcd(int a, int b) {if(b == 0) { return a; }return gcd(b, a % b);}int main(void) {scanf("%d%d%d", &p, &q, &n);int i;for(i = 0; i < n; i++) {scanf("%d%d", &x[i], &y[i]);}int d = gcd(p, q), counter = 0;for(i = 0; i < n; i++) {if(p != 0 && q != 0) {if( x[i] % d == 0 && y[i] % d == 0 &&(( (p / d) % 2 == 0 || (q / d) % 2 == 0 ) ||(x[i] / d + y[i] / d) % 2 == 0)) { counter++; }} else if(p == 0 && q != 0) {if( x[i] % q == 0 && y[i] % q == 0 ) { counter++; }} else if(p != 0 && q == 0) {if( x[i] % p == 0 && y[i] % p == 0 ) { counter++; }} else {if( x[i] == 0 && y[i] == 0 ) { counter++; }}}printf("%d\n", counter);return 0;}