結果

問題 No.1140 EXPotentiaLLL!
ユーザー takumattakumat
提出日時 2020-08-01 07:15:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 701 ms / 2,000 ms
コード長 1,732 bytes
コンパイル時間 837 ms
コンパイル使用メモリ 88,396 KB
実行使用メモリ 39,140 KB
最終ジャッジ日時 2023-09-21 18:43:55
合計ジャッジ時間 10,160 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 440 ms
39,024 KB
testcase_01 AC 436 ms
38,940 KB
testcase_02 AC 438 ms
38,936 KB
testcase_03 AC 575 ms
39,004 KB
testcase_04 AC 481 ms
39,140 KB
testcase_05 AC 664 ms
38,804 KB
testcase_06 AC 623 ms
39,012 KB
testcase_07 AC 701 ms
39,000 KB
testcase_08 AC 156 ms
38,872 KB
testcase_09 AC 165 ms
38,808 KB
testcase_10 AC 159 ms
38,844 KB
testcase_11 AC 154 ms
39,004 KB
testcase_12 AC 153 ms
38,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007; //998244353;

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template <class _T> static _T tp_abs(_T a) {
	if (a < (_T)0) {
		a *= (_T)-1;
	}
	return a;
}

static void exec();

int main()
{
	exec();
	fflush(stdout);
	return 0;
}

static void eratosthenes(int targ, std::set<int>& primes)
{
	std::vector<int> is_prime(targ + 1, 1);

	for (int i = 2; i * i <= targ; i++) {
		if (is_prime[i]) {
			for (int j = 0; (i * (j + 2)) <= targ; j++) {
				is_prime[i * (j + 2)] = 0;
			}
		}
	}

	for (int i = 2; i <= targ; i++) {
		if (is_prime[i]) primes.insert(i);
	}
}
template <class _T> static _T tp_modpow(_T base, _T exp, _T mod = (_T)1) {
	_T ans = 1;
	while (exp > 0) {
		if (exp & 1) {
			ans = (ans * base) % mod;
		}
		base = (base * base) % mod;
		exp >>= 1;
	}
	return ans;
}
template <class _T> static _T tp_modinv(_T a, _T mod) {
	return tp_modpow<_T>(a, mod - 2, mod);
}

static void exec()
{
	int T;
	get(T);

	std::set<int> primes;
	eratosthenes(5 * 1000000 + 1, primes);

	LLONG A;
	int P;

	while (T--) {
		scanf("%lld %d", &A, &P);

		LLONG ans = -1;
		if (primes.find(P) != primes.end()) {
			if (A % P) {
				ans = 1;
			}
			else {
				ans = 0;
			}
		}
		printf("%lld\n", ans);
	}
}
0