結果
| 問題 |
No.1140 EXPotentiaLLL!
|
| ユーザー |
lorent_kyopro
|
| 提出日時 | 2020-08-01 03:39:26 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,220 ms / 2,000 ms |
| コード長 | 2,198 bytes |
| コンパイル時間 | 2,968 ms |
| コンパイル使用メモリ | 196,664 KB |
| 最終ジャッジ日時 | 2025-01-12 12:09:01 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 12 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}
struct Sieve {
int n;
vector<int> f, primes;
Sieve(int n=1) : n(n), f(n+1) {
f[0] = f[1] = -1;
for (long long i = 2; i <= n; ++i) {
if (f[i]) continue;
primes.push_back(i);
f[i] = i;
for (long long j = i*i; j <= n; j += i) {
if (!f[j]) f[j] = i;
}
}
}
bool isPrime(int x) { return f[x] == x;}
vector<int> factorList(int x) {
vector<int> res;
while (x != 1) {
res.push_back(f[x]);
x /= f[x];
}
return res;
}
vector<pair<int, int>> factor(int x) {
vector<int> fl = factorList(x);
if (fl.size() == 0) return {};
vector<pair<int, int>> res(1, pair<int, int>(fl[0], 0));
for (int p : fl) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
} sieve(5e6);
void solve() {
ll a, p;
cin >> a >> p;
if (!sieve.isPrime(p)) {
cout << -1 << endl;
} else {
if (a % p == 0) {
cout << 0 << endl;
} else {
cout << 1 << endl;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) solve();
}
lorent_kyopro