結果

問題 No.1140 EXPotentiaLLL!
ユーザー trineutron
提出日時 2020-08-01 23:51:35
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 383 ms / 2,000 ms
コード長 626 bytes
コンパイル時間 413 ms
コンパイル使用メモリ 27,776 KB
最終ジャッジ日時 2025-01-12 13:00:40
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:15:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |     scanf("%d", &t);
      |     ~~~~~^~~~~~~~~~
main.cpp:18:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |         scanf("%ld %ld", &a, &p);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <cstdio>

int main() {
    bool isprime[5000001];
    isprime[1] = false;
    for (int i = 2; i <= 5000000; i++) {
        isprime[i] = true;
    }
    for (int i = 2; i * i <= 5000000; i++) {
        for (int j = 2; j * i <= 5000000; j++) {
            isprime[j * i] = false;
        }
    }
    int t;
    scanf("%d", &t);
    for (int i = 0; i < t; i++) {
        long a, p;
        scanf("%ld %ld", &a, &p);
        if (isprime[p]) {
            if (a % p == 0) {
                puts("0");
            } else {
                puts("1");
            }
        } else {
            puts("-1");
        }
    }
}
0