結果

問題 No.1140 EXPotentiaLLL!
ユーザー tyawanmusityawanmusi
提出日時 2020-07-31 22:07:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 673 bytes
コンパイル時間 534 ms
コンパイル使用メモリ 68,576 KB
実行使用メモリ 12,212 KB
最終ジャッジ日時 2023-09-20 23:32:39
合計ジャッジ時間 7,652 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <math.h>
using namespace std;
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
int main(){
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        long long a;
        int p;
        cin >> a >> p;
        if (IsPrime(p)) cout << -1 << endl;
        else cout << 1 << endl;
    }
}
0