結果
| 問題 | No.1140 EXPotentiaLLL! |
| コンテスト | |
| ユーザー |
Asdf_QwertyZ
|
| 提出日時 | 2020-08-01 00:45:37 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 283 ms / 2,000 ms |
| コード長 | 1,799 bytes |
| コンパイル時間 | 667 ms |
| コンパイル使用メモリ | 81,416 KB |
| 実行使用メモリ | 14,172 KB |
| 最終ジャッジ日時 | 2024-07-06 23:02:50 |
| 合計ジャッジ時間 | 4,492 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 12 |
ソースコード
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
constexpr ll INF = 1ll<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }
template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }
ll T;
bool used[5000010];
std::vector<ll> primes;
void sieve() {
used[0] = used[1] = true;
for( ll i = 2; i <= 5000000; ++i ) if( !used[i] ) {
primes.emplace_back( i );
for( ll j = i; j <= 5000000; j += i )
used[j] = true;
}
return;
}
int main()
{
sieve();
scanf( "%lld", &T );
rep( t, T ) {
ll A, P;
scanf( "%lld%lld", &A, &P );
ll p = *std::lower_bound( all(primes), P );
if( p != P ) {
puts("-1");
continue;
}
A %= P;
if( P > 2 ) {
printf( "%lld\n", !A ? 0 : 1 );
} else {
printf( "%lld\n", A*A%P );
}
}
return 0;
}
Asdf_QwertyZ