結果

問題 No.2682 Visible Divisible
ユーザー Taiki0715Taiki0715
提出日時 2024-03-20 21:26:22
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 4,837 bytes
コンパイル時間 5,784 ms
コンパイル使用メモリ 324,576 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-03-20 21:26:30
合計ジャッジ時間 8,007 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
6,548 KB
testcase_01 AC 79 ms
6,548 KB
testcase_02 AC 82 ms
6,548 KB
testcase_03 AC 77 ms
6,548 KB
testcase_04 AC 37 ms
6,548 KB
testcase_05 AC 38 ms
6,548 KB
testcase_06 AC 39 ms
6,548 KB
testcase_07 AC 37 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 2 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 44 ms
6,548 KB
testcase_12 AC 40 ms
6,548 KB
testcase_13 AC 37 ms
6,548 KB
testcase_14 AC 74 ms
6,548 KB
testcase_15 AC 52 ms
6,548 KB
testcase_16 AC 41 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
template<int mod>istream &operator>>(istream &is,static_modint<mod> &a){long long b;is>>b;a=b;return is;}
istream &operator>>(istream &is,modint &a){long long b;cin>>b;a=b;return is;}
#endif
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) static_cast<void>(0)
#define debugg(...) static_cast<void>(0)
template<typename T1,typename T2>ostream &operator<<(ostream &os,const pair<T1,T2>&p){os<<p.first<<' '<<p.second;return os;}
#endif
using ll=long long;
using ull=unsigned long long;
using P=pair<ll,ll>;
template<typename T>using minque=priority_queue<T,vector<T>,greater<T>>;
template<typename T>bool chmax(T &a,const T &b){return (a<b?(a=b,true):false);}
template<typename T>bool chmin(T &a,const T &b){return (a>b?(a=b,true):false);}
template<typename T1,typename T2>istream &operator>>(istream &is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T>istream &operator>>(istream &is,vector<T> &a){for(auto &i:a)is>>i;return is;}
template<typename T1,typename T2>void operator++(pair<T1,T2>&a,int n){a.first++,a.second++;}
template<typename T1,typename T2>void operator--(pair<T1,T2>&a,int n){a.first--,a.second--;}
template<typename T>void operator++(vector<T>&a,int n){for(auto &i:a)i++;}
template<typename T>void operator--(vector<T>&a,int n){for(auto &i:a)i--;}
#define reps(i,a,n) for(int i=(a);i<(n);i++)
#define rep(i,n) reps(i,0,n)
#define all(x) x.begin(),x.end()
#define pcnt(x) __builtin_popcountll(x)
#define fin(x) return cout<<x<<'\n',static_cast<void>(0)
ll myceil(ll a,ll b){return (a+b-1)/b;}
template<typename T,size_t n,size_t id=0>
auto vec(const int (&d)[n],const T &init=T()){
  if constexpr (id<n)return vector(d[id],vec<T,n,id+1>(d,init));
  else return init;
}
void SOLVE();
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<fixed<<setprecision(16);
  #ifdef LOCAL
  clock_t start=clock();
  #endif
  int testcase=1;
  //cin>>testcase;
  for(int i=0;i<testcase;i++){
    SOLVE();
  }
  #ifdef LOCAL
  cerr<<"time:";
  cerr<<(clock()-start)/1000;
  cerr<<"ms\n";
  #endif
}
bool isprime(ull n)noexcept{
  if(n<=1)return false;
  if(n%2==0)return n==2;
  ull d=n-1;
  int s=0;
  while(!(d&1))d>>=1,s++;
  int q=63;
  while(!(d>>q))q--;
  ull r=n;
  for(int i=0;i<5;i++)r*=2-r*n;
  assert(r*n==1);
  auto redc=[&r,&n](__uint128_t x)->ull {
    x=(x+__uint128_t(ull(x)*-r)*n)>>64;
    return x>=n?x-n:x;
  };
  __uint128_t r2=-__uint128_t(n)%n;
  ull one=redc(r2);
  for(ull base:{2,325,9375,28178,450775,9780504,1795265022}){
    if(base%n==0)continue;
    ull a=base=redc((base%n)*r2);
    for(int i=q-1;i>=0;i--){
      a=redc(__uint128_t(a)*a);
      if(d>>i&1)a=redc(__uint128_t(a)*base);
    }
    if(a==one)continue;
    for(int i=1;a!=n-one;i++){
      if(i>=s)return false;
      a=redc(__uint128_t(a)*a);
    }
  }
  return true;
}
vector<ull>factorize(ull n)noexcept{
  vector<ull>ret;
  auto div=[](ull x)noexcept->ull {
    ull r=x;
    for(int i=0;i<5;i++)r*=2-r*x;
    ull r2=-__uint128_t(x)%x;
    auto redc=[&r,&x](__uint128_t t)->ull {
      t=(t+__uint128_t(ull(t)*-r)*x)>>64;
      return t>=x?t-x:t;
    };
    ull a=0,b=0;
    const ull one=redc(r2);
    ull e=one;
    ull m=1ll<<((63-__builtin_clzll(x))>>3);
    while(true){
      ull ca=a,cb=b;
      ull sk=one;
      rep(i,m){
        a=redc(__uint128_t(a)*a+e);
        b=redc(__uint128_t(b)*b+e);
        b=redc(__uint128_t(b)*b+e);
        ull c=redc(a),d=redc(b);
        sk=redc(__uint128_t(sk)*(c>d?c-d:d-c));
      }
      ull g=gcd(redc(sk),x);
      if(g>1){
        if(g<x)return g;
        rep(i,m){
          ca=redc(__uint128_t(ca)*ca+e);
          cb=redc(__uint128_t(cb)*cb+e);
          cb=redc(__uint128_t(cb)*cb+e);
          ull c=redc(ca),d=redc(cb);
          ull cg=gcd(c>d?c-d:d-c,x);
          if(cg>1){
            if(cg<x)return cg;
            else{
              e+=one;
              a=b=0;
              break;
            }
          }
        }
      }
    }
  };
  stack<ull>st;
  while(!(n&1)){
    n>>=1;
    ret.push_back(2);
  }
  if(n==1)return ret;
  st.push(n);
  while(!st.empty()){
    ull now=st.top();
    st.pop();
    if(isprime(now)){
      ret.push_back(now);
      continue;
    }
    ull d=div(now);
    st.push(d);
    now/=d;
    if(now!=1)st.push(now);
  }
  return ret;
}
void SOLVE(){
  int n;
  ll k;
  cin>>n>>k;
  auto f=factorize(k);
  unordered_map<ll,int>kf;
  for(auto i:f)kf[i]++;
  unordered_map<ll,int>cnt;
  rep(i,n){
    ll a;
    cin>>a;
    unordered_map<ll,int>now;
    for(auto [key,val]:kf){
      while(a%key==0){
        a/=key;
        now[key]++;
      }
    }
    for(auto [key,val]:now)chmax(cnt[key],val);
  }
  for(auto [key,val]:kf)if(cnt[key]<val)fin("No");
  cout<<"Yes"<<endl;
}
0