結果

問題 No.3708 Uncommon Time
コンテスト
ユーザー umezo
提出日時 2026-09-11 23:54:49
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 2,000 ms
+ 411µs
コード長 1,352 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,976 ms
コンパイル使用メモリ 333,404 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-09-11 23:55:54
合計ジャッジ時間 4,680 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;

#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--)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
template <class T> using V=vector<T>;
template <class T> using VV=V<V<T>>;
using u128=__int128_t;
using ll=long long;

template<class T> T modpow(T x,T n,T MOD){
  T ans=1;
  while(n){
    if(n&1) ans=ans*x%MOD;
    x=x*x%MOD;
    n/=2;
  }
  return ans;
}

// Miller-Rabin 素数判定(2^64以下なら確定)
bool is_prime(ll n){
  if(n<=1) return false;
  if(n==2) return true;
  if(n%2==0) return false;
  vector<ll> A={2,325,9375,28178,450775,9780504,1795265022};
  ll s=0,d=n-1;
  while(d%2==0){ //n-1=2^s*d (dは奇数)
    ++s;
    d>>=1;
  }
  for(auto a:A){
    if(a%n==0) return true;
    ll t,x=modpow<__int128_t>(a,d,n);
    if(x!=1){ //a^d≡1 ならほぼ素数
      for(t=0;t<s;++t){
        if(x==n-1) break; //a^(2^t*d)≡-1 (すべてのtで)ならほぼ素数
        x=__int128_t(x)*x%n;
      }
      if(t==s) return false; //どちらも当てはまらないなら合成数
    }
  }
  return true; //A全てで素数判定なら確定
}

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int m,d;
  cin>>m>>d;
  int a=100*m+d;
  if(is_prime(a)) cout<<"Yes\n";
  else cout<<"No\n";

  return 0;
}
0