結果
| 問題 | No.3708 Uncommon Time |
| コンテスト | |
| ユーザー |
kwm_t
|
| 提出日時 | 2026-09-11 21:26:02 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 1 ms / 2,000 ms |
| + 243µs | |
| コード長 | 3,504 bytes |
| 記録 | |
| コンパイル時間 | 2,027 ms |
| コンパイル使用メモリ | 333,400 KB |
| 実行使用メモリ | 6,528 KB |
| 最終ジャッジ日時 | 2026-09-11 21:56:43 |
| 合計ジャッジ時間 | 4,278 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 55 |
ソースコード
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
// using namespace atcoder;
// using mint = modint1000000007;
// const int mod = 1000000007;
// using mint = modint998244353;
// const int mod = 998244353;
// const int INF = 1e9;
// const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, l, r) for (int i = (l); i < (r); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, l, r) for (int i = (r)-1; i >= (l); --i)
#define all(x) (x).begin(), (x).end()
#define allR(x) (x).rbegin(), (x).rend()
#define P pair<int, int>
template<typename A, typename B> inline bool chmax(A& a, const B& b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A& a, const B& b) { if (a > b) { a = b; return true; } return false; }
#ifndef KWM_T_BASE_INTEGR_HPP
#define KWM_T_BASE_INTEGR_HPP
#include <vector>
/**
* @brief ローカル環境用(MSC)int128
*/
#ifdef _MSC_VER
using int128 = long long;
#else
using int128 = __int128;
#endif
#endif // KWM_T_BASE_INTEGR_HPP
#ifndef KWM_T_MATH_IS_PRIME_HPP
#define KWM_T_MATH_IS_PRIME_HPP
#include <cstdint>
#include <vector>
//#include "base/integer.hpp"
namespace kwm_t::math {
namespace detail {
/**
* @brief a^e mod m を計算する。
*
* 計算量:
* O(log e)
*
* @param a 底。
* @param e 指数。
* @param m 法。
*
* 制約 / 注意:
* - m > 0 を仮定する。
* - __int128 をサポートするコンパイラが必要。
*/
inline long long mod_pow(int128 a, long long e, long long m) {
int128 ret = 1;
while (e > 0) {
if (e & 1) {
ret = ret * a % m;
}
a = a * a % m;
e >>= 1;
}
return static_cast<long long>(ret);
}
} // namespace detail
/**
* @brief Miller-Rabin 法により n が素数か判定する。
*
* 計算量:
* O(log n)
*
* 制約 / 注意:
* - n >= 0 を仮定する。
* - Miller-Rabin 法による素数判定。
* - 一般の n に対しては確率的アルゴリズムだが、
* 基底 {2, 3, 5, 7, 11} を用いる本実装では、
* n <= 10^12 の範囲において誤りなく素数判定を行える。
* 基底 {2, 325, 9375, 28178, 450775, 9780504, 1795265022} を用いる本実装では、
* n < 2^64 の範囲において誤りなく素数判定を行える。
* - __int128 をサポートするコンパイラが必要。
*
* 使用例:
* bool p1 = is_prime(2); // true
* bool p2 = is_prime(1000000007); // true
* bool p3 = is_prime(1000000008); // false
*
* verified:
* -
*/
inline bool is_prime(long long n) {
if (n <= 2) return n == 2;
if (n % 2 == 0) return false;
const std::vector<long long> a_list = { 2, 3, 5, 7, 11 };
// const std::vector<long long> a_list = { 2, 325, 9375, 28178, 450775, 9780504, 1795265022 };
// n - 1 = d * 2^s (d は奇数)
long long d = (n - 1) / ((n - 1) & (1 - n));
for (long long a : a_list) {
long long t = d;
a = detail::mod_pow(a, t, n);
if (a == 0 || a == 1) continue;
while (a != n - 1) {
t *= 2;
if (t == n - 1) return false;
a = static_cast<long long>(static_cast<int128>(a) * a % n);
if (a == 1) return false;
}
}
return true;
}
} // namespace kwm_t::math
#endif // KWM_T_MATH_IS_PRIME_HPP
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int a, b; cin >> a >> b;;
int x = a * 100 + b;
if (kwm_t::math::is_prime(x))cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}
kwm_t