結果
問題 |
No.1140 EXPotentiaLLL!
|
ユーザー |
![]() |
提出日時 | 2020-07-31 21:46:04 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 260 ms / 2,000 ms |
コード長 | 918 bytes |
コンパイル時間 | 2,074 ms |
コンパイル使用メモリ | 197,084 KB |
最終ジャッジ日時 | 2025-01-12 09:42:54 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 12 |
ソースコード
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define DEBUG(...) #endif vector<int> sieve(int n) { vector<bool> b(n / 3 + 1, true); vector<int> res{2, 3}; for (int p = 5, d = 4; p * p <= n; p += d = 6 - d) if (b[p / 3]) for (int i = p * p, di = p % 3 * 2 * p; i <= n; i += di = 6 * p - di) b[i / 3] = false; for (int p = 5, d = 4; p <= n; p += d = 6 - d) if(b[p / 3]) res.push_back(p); while (not res.empty() and res.back() > n) res.pop_back(); return res; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); auto primes = sieve(5e6); int tt; cin >> tt; using ll = long long; while (tt--) { ll a; cin >> a; int p; cin >> p; if (binary_search(begin(primes), end(primes), p)) { if (a % p) { cout << "1\n"; } else { cout << "0\n"; } } else { cout << "-1\n"; } } }