結果

問題 No.1140 EXPotentiaLLL!
ユーザー jutamajutama
提出日時 2021-05-02 01:22:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 877 ms / 2,000 ms
コード長 5,583 bytes
コンパイル時間 3,963 ms
コンパイル使用メモリ 186,028 KB
実行使用メモリ 13,680 KB
最終ジャッジ日時 2023-09-27 14:28:14
合計ジャッジ時間 13,929 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 877 ms
13,472 KB
testcase_01 AC 843 ms
13,500 KB
testcase_02 AC 874 ms
13,664 KB
testcase_03 AC 670 ms
13,676 KB
testcase_04 AC 547 ms
13,556 KB
testcase_05 AC 813 ms
13,556 KB
testcase_06 AC 773 ms
13,668 KB
testcase_07 AC 845 ms
13,680 KB
testcase_08 AC 109 ms
13,472 KB
testcase_09 AC 104 ms
13,628 KB
testcase_10 AC 106 ms
13,600 KB
testcase_11 AC 108 ms
13,508 KB
testcase_12 AC 108 ms
13,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <bitset>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using namespace atcoder;

typedef long long ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::pair<ld, ld> pid;
typedef std::pair<ll, std::string> pls;
typedef std::vector<bool> vb;
typedef std::vector<vb> vvb;
typedef std::vector<int> vi;
typedef std::vector<vi> vvi;
typedef std::vector<vvi> vvvi;
typedef std::vector<vvvi> vvvvi;
typedef std::vector<ll> vl;
typedef std::vector<vl> vvl;
typedef std::vector<vvl> vvvl;
typedef std::vector<vvvl> vvvvl;
typedef std::vector<ld> vd;
typedef std::vector<vd> vvd;
typedef std::vector<std::string> vs;
#define rep(i,n) for(auto i=0; i<n; ++i)
#define repm(i,s,n) for(auto i=s; i<n; ++i)
#define repd(i,n) for(auto i=n-1; i>=0; --i)
#define repdm(i,e,n) for(auto i=n-1; i>=e; --i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

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 mint, internal::is_modint_t<mint>* = nullptr>
constexpr istream& operator>>(istream& is, mint& x) noexcept {long long v = 0; std::cin >> v; x = v; return is;}
template <class mint, internal::is_modint_t<mint>* = nullptr>
constexpr ostream& operator<<(ostream& os, const mint& x) noexcept {os << x.val(); return os;}
inline void _n() { std::cout << std::endl; }
template <class T> inline void _(const T a) { std::cout << a; }
template <class T> inline void _l(const T a) { _(a); _n(); }
template <class T> inline void _s(const T a) { _(a); _(' '); }
template <class T> inline void _v(const std::vector<T> v) { for(auto a : v) _(a); }
template <class T> inline void _vl(const std::vector<T> v) { for(auto a : v) _l(a); }
template <class T> inline void _vs(const std::vector<T> v) { for(auto a : v) _s(a); _n(); }
template <class T> inline void _vvl(const std::vector<std::vector<T>> v) { for(auto a : v) { _v(a); _n(); } }
template <class T> inline void _vvs(const std::vector<std::vector<T>> v) { for(auto a : v) { _vs(a); } }
inline void ynl(const bool b) {_l(b ? "yes" : "no");}
inline void yns(const bool b) {_l(b ? "Yes" : "No");}
inline void ynu(const bool b) {_l(b ? "YES" : "NO");}

const int INF = 1 << 30;
const long long INF_LL = 1LL << 62;
const long long MOD1 = 1000000007;
const long long MOD9 = 998244353;
using mint1 = atcoder::modint1000000007;
using mint9 = atcoder::modint998244353;


//* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *//

void input() {
   
    
}

struct sieve_E {

    public :
    sieve_E(long long n) : _n(n) {
        size = (_n/spp + 1) * srl;
        sieve = vector<bool>(size, true);
        sieving_prime = vector<unsigned long long>(size, 0);

        sieving();
    }

    bool is_prime(long long n) {
        assert(0 <= n && n <= _n);
        if (n == 0 || n == 1) return false;
        for (auto p : sp) {if(n == p) return true; if(n%p == 0) return false;}
        return sieve[ntoi(n)];
    }
    unsigned long long get_sieving_prime(long long n) {
        assert(0 <= n && n <= _n);
        if (n == 0 || n == 1) return 0;
        for (auto p : sp) {if(n%p == 0) return p;}
        if (is_prime(n)) return n;
        return sieving_prime[ntoi(n)];
    }
    unsigned long long get_sieve_size() {return _n;}

    private :
    long long _n;

    unsigned long long size;
    std::vector<bool> sieve;
    std::vector<unsigned long long> sieving_prime;

    const std::vector<unsigned int> sp = {2, 3, 5};                      // skip primes
    const std::vector<unsigned int> sr = {1, 7, 11, 13, 17, 19, 23, 29}; // stand reminders
    const unsigned int spp = 2 * 3 * 5;                                  // skip primes product
    const unsigned int srl = 8;                                          // stand reminders length

    void sieving() {
        unsigned long long max_i = ((unsigned long long)sqrt(_n)/spp + 1) * srl;
        for (unsigned long long i = 1; i <= max_i ; ++i) {
            if(!sieve[i]) continue;

            unsigned long long num_i = (unsigned long long)iton(i);
            for (unsigned long long j = num_i * num_i; j < (unsigned long long)_n; j += num_i) {
                long long idx_j = ntoi(j);
                if(idx_j > 0) {
                    sieve[idx_j] = false;
                    sieving_prime[idx_j] = num_i;
                }
            }
        }
    }

    unsigned long long iton(unsigned long long idx) {
        return (unsigned long long) ((idx/srl) * spp + sr[idx%srl]);
    }
    long long ntoi(unsigned long long num) {
        unsigned int sri = (unsigned int)(std::find(sr.begin(), sr.end(), num%spp) - sr.begin());
        return sri == srl ? -1 : (num/spp) * srl + sri;
    }
};

void solve() {
    
    
    sieve_E sieve(5000000);
    
    int T; cin >> T;
    
    rep(i, T) {
        ll A, P; cin >> A >> P;
        _l(sieve.is_prime(P) ? A%P != 0 : -1);
    }
    
    
    
    
}

//* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *//

int main() {
    
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
    std::cin.tie(0);
    ios::sync_with_stdio(false);
    
    input();
    solve();
    
    return 0;
}
0