結果
| 問題 |
No.1140 EXPotentiaLLL!
|
| ユーザー |
|
| 提出日時 | 2021-04-29 16:26:57 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,193 ms / 2,000 ms |
| コード長 | 2,124 bytes |
| コンパイル時間 | 1,460 ms |
| コンパイル使用メモリ | 167,120 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-16 01:35:18 |
| 合計ジャッジ時間 | 12,552 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 12 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ \
std::cout << PREFIX << #x << " = " << x << std::endl; \
}
std::ostream& output_indent(std::ostream& os, int ind) {
for(int i = 0; i < ind; i++) os << " ";
return os;
}
template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p);
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);
template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) {
return (os << "(" << p.first << ", " << p.second << ")");
}
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
os << "[";
for(int i = 0;i < v.size();i++) os << v[i] << ", ";
return (os << "]");
}
template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
Cond cond; chain(Cond cond) : cond(cond) {}
template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }
int main() {
int T;
cin >> T;
const i64 MAX = 5050505;
std::bitset<MAX> prime;
prime.flip();
prime.reset(0);
prime.reset(1);
for(int i = 2; i < MAX; i++) {
if(prime[i]) {
for(int j = i + i; j < MAX; j += i) {
prime.reset(j);
}
}
}
auto func = [&](i64 a, i64 p) {
if(!prime.test(p)) return -1ll;
if(a % p == 0) {
return 0ll;
}
else {
return 1ll;
}
};
while(T--) {
i64 a, p;
cin >> a >> p;
std::cout << func(a, p) << std::endl;
}
}