結果

問題 No.1140 EXPotentiaLLL!
ユーザー Asdf_QwertyZAsdf_QwertyZ
提出日時 2020-08-01 00:45:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 314 ms / 2,000 ms
コード長 1,799 bytes
コンパイル時間 979 ms
コンパイル使用メモリ 80,904 KB
実行使用メモリ 13,408 KB
最終ジャッジ日時 2023-09-21 04:26:19
合計ジャッジ時間 5,188 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 240 ms
12,264 KB
testcase_01 AC 204 ms
12,320 KB
testcase_02 AC 241 ms
12,184 KB
testcase_03 AC 215 ms
12,268 KB
testcase_04 AC 175 ms
12,852 KB
testcase_05 AC 257 ms
12,220 KB
testcase_06 AC 245 ms
12,884 KB
testcase_07 AC 314 ms
12,680 KB
testcase_08 AC 43 ms
12,356 KB
testcase_09 AC 42 ms
12,716 KB
testcase_10 AC 42 ms
13,408 KB
testcase_11 AC 42 ms
12,848 KB
testcase_12 AC 41 ms
12,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0