Problem:
D: mod rally
問題
Reider 君は北海道大学にスタンプを押すのが趣味です。
そこで Reider 君は、$N$ 個の整数 $a_i$ ($1\leq i\leq N$) を用いて、いろいろな種類のスタンプを押すことにしました。
Reider 君ははじめ $1$ と書かれたスタンプを持っています。Reider 君は、次の操作を行うことができます。
スタンプに $x$ と書かれているとき、ある $i$ ($1\leq i\leq N$) を選び $(x\times a_i) \bmod{M}$ に書き換える。
スタンプは任意のタイミングで押すことができます。Reider 君が $0$ 以上 $M-1$ 以下の全てのスタンプを押すことができるか判定してください。
入力形式
$N$ $M$
$a_1$ $a_2$ ... $a_N$
整数 $N$ と $M$ が一行目に与えられ、$N$ 個の整数 $a_i$ ($1 \leq i \leq N$) が二行目に与えられる。
制約
$1 \leq N \leq 2\times 10^3$
$2 \leq M \leq 2\times 10^3$
$1 \leq a_i \leq 10^9$ ($1 \leq i \leq N$)
入力は全て整数
出力形式
Reider 君が $M$ 種類のスタンプを押すことができるなら
Yes
を、不可能なら
No
を出力してください。
入力例 1
2 4
2 3
出力例 1
Yes
Reider 君は、次のように操作を行うことで、4 種類のスタンプを押すことができます。
$1$ が書かれたスタンプを押す。
数列の要素 $a_2 = 3$ を使うことで、スタンプに書かれた整数を $(1 \times 3) \bmod 4 = 3$ に書き換える。
$3$ が書かれたスタンプを押す。
数列の要素 $a_1 = 2$ を使うことで、スタンプに書かれた整数を $(3 \times 2) \bmod 4 = 2$ に書き換える。
$2$ が書かれたスタンプを押す。
数列の要素 $a_1 = 2$ を使うことで、スタンプに書かれた整数を $(2 \times 2) \bmod 4 = 0$ に書き換える。
$0$ が書かれたスタンプを押す。
入力例 2
2 4
1 4
出力例 2
No
Reider 君はどのように操作を行っても、$4$ 種類のスタンプを押すことができません。

Submitted solutions:

code_snippet: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)

using namespace std;
using ll = long long;
using P = pair<int,int>;
const int mod = 998244353;
const int inf = (1<<30);

const int dy[4] = {-1,0,0,1};
const int dx[4] = {0,-1,1,0};

// internal csr
namespace atcoder {
    namespace internal {
        template <class E> struct csr {
            std::vector<int> start;
            std::vector<E> elist;
            explicit csr(int n, const std::vector<std::pair<int, E>> & edges)
                :start(n+1), elist(edges.size()) {
                    for (auto e : edges) {
                        start[e.first + 1]++;
                    }
                    for(int i=1; i<= n; i++) {
                        start[i] += start[i-1];
                    }
                    auto counter = start;
                    for(auto e : edges) {
                        elist[counter[e.first]++] = e.second;
                    }
                }
        };
    }
}

// internal scc
namespace atcoder {
    namespace internal {
        struct scc_graph {
            public:
                explicit scc_graph(int n) : _n(n) {}

                int num_vertices() { return _n; }

                void add_edge(int from, int to) { edges.push_back({from, {to}}); }

                std::pair<int, std::vector<int>> scc_ids() {
                    auto g = csr<edge>(_n, edges);
                    int now_ord = 0, group_num = 0;
                    std::vector<int> visited, low(_n), ord(_n, -1), ids(_n);
                    visited.reserve(_n);
                    auto dfs = [&](auto self, int v) -> void {
                        low[v] = ord[v] = now_ord++;
                        visited.push_back(v);
                        for (int i=g.start[v]; i < g.start[v+1]; i++) {
                            auto to = g.elist[i].to;
                            if(ord[to] == -1) {
                                self(self, to);
                                low[v] = std::min(low[v], low[to]);
                            } else {
                                low[v] = std::min(low[v], ord[to]);
                            }
                        }

                        if(low[v] == ord[v]) {
                            while(true) {
                                int u = visited.back();
                                visited.pop_back();
                                ord[u] = _n;
                                ids[u] = group_num;
                                if(u == v) break;
                            }
                            group_num++;
                        }
                    };
                    for(int i=0;i<_n;i++) {
                        if(ord[i] == -1) dfs(dfs,i);
                    }
                    for(auto &x:ids) {
                        x = group_num -1 -x;
                    }
                    return {group_num, ids};
                }


                std::vector<std::vector<int>> scc() {
                    auto ids = scc_ids();
                    int group_num = ids.first;
                    std::vector<int> counts(group_num);
                    for(auto x:ids.second) counts[x]++;
                    std::vector<std::vector<int>> groups(ids.first);
                    for(int i=0;i<group_num;i++) {
                        groups[i].reserve(counts[i]);
                    }
                    for(int i=0;i<_n;i++) {
                        groups[ids.second[i]].push_back(i);
                    }
                    return groups;
                }
            private:
                int _n;
                struct edge {
                    int to;
                };
                std::vector<std::pair<int, edge>> edges;
        };
    }
}


// scc
namespace atcoder {
    struct scc_graph {
        public:
            scc_graph() : internal(0) {}
            explicit scc_graph(int n) : internal(n) {}

            void add_edge(int from, int to) {
                int n = internal.num_vertices();
                assert(0 <= from && from < n);
                assert(0 <= to && to < n);
                internal.add_edge(from, to);
            }

            std::vector<std::vector<int>> scc() {
                return internal.scc();
            }

        private:
            internal::scc_graph internal;
    };
}

using namespace atcoder;


vector<int> topological_sort(vector<vector<int>> G, vector<int> indeg) {
    int n = G.size();

    queue<int> que;
    vector<int> used(n, 0);
    auto push=[&](int v) {
        if(used[v]) return;
        que.emplace(v);
        used[v] = 1;
    };

    for(int i=0;i<n;i++) {
        if(indeg[i]==0) {
            push(i);
        }
    }

    vector<int> ps;
    while(!que.empty()) {
        int v = que.front();que.pop();
        ps.emplace_back(v);
        for(int u:G[v]) {
            indeg[u]--;
            if(indeg[u]==0) push(u);
        }
    }

    if(n!=(int)ps.size()) return {};
    return ps;
}


int main(){
    ll n,m;
    cin>>n>>m;

    vector<ll> a(n);
    for(auto &v:a) {
        cin>>v;
    }

    vector<vector<ll>> adj_matrix(m, vector<ll>(m, 0));
    rep(x, m) {
        rep(i, n) {
            ll to = (x * a[i]) % m;
            adj_matrix[x][to] = 1;
        }
    }

//    rep(i, m) {
//        rep(j, m) {
//            if(j) {
//                cout << ' ';
//            }
//            cout << adj_matrix[i][j];
//        }
//        cout << endl;
//    }


    scc_graph sg(m);
    rep(x, m) {
        rep(to, m) {
            if(adj_matrix[x][to]) {
                sg.add_edge(x, to);
            }
        }
    }

    auto scc = sg.scc();

//    rep(i, scc.size()) {
//        rep(j, scc[i].size()) {
//            int v = scc[i][j];
//            if(j) {
//                cout << ' ';
//            }
//            cout << v;
//        }
//        cout << endl;
//    }

    map<int, int> v_to_scc_id;
    rep(i, scc.size()) {
        rep(j, scc[i].size()) {
            int v = scc[i][j];
            v_to_scc_id[v] = i;
        }
    }

    set<pair<int,int>> edges;
    vector<vector<int>> g(scc.size());
    vector<int> indeg(scc.size(), 0);
    rep(x, m) {
        rep(to, m) {
            if(adj_matrix[x][to]) {
                int scc_id1 = v_to_scc_id[x];
                int scc_id2 = v_to_scc_id[to];

                if(scc_id1 != scc_id2) {
                    g[scc_id1].push_back(scc_id2);
                    indeg[scc_id2]++;
                    edges.emplace(scc_id1, scc_id2);
                }
            }
        }
    }

//    for(auto e : edges) {
//        int from = e.first;
//        int to = e.second;
//        cout << "from:" << from << " to:" << to << endl;
//    }

    auto sorted_ids = topological_sort(g, indeg);

    bool ans = true;
    for(int i=0;i<(int)sorted_ids.size()-1;i++) {
        int now = sorted_ids[i];
        int next = sorted_ids[i+1];

        if (edges.find(make_pair(now, next)) == edges.end()) { // not found
            ans = false;
            break;
        }
    }

    cout << (ans ? "Yes" : "No") << endl;
}
accuracy: 1
time_ms: 150
memory_kb: 56752
final_rank: 10

code_snippet: #include<bits/stdc++.h>

using namespace std;

namespace luz {

  using usize = std::size_t;

}

namespace luz {

  template< typename T >
  struct Edge {
    using cost_type = T;

    usize from, to;
    T cost;
    usize id;

    Edge() = default;

    Edge(usize f, usize t, T c, usize i) : from(f), to(t), cost(c), id(i) {}
  };

}

namespace luz {

  template< typename Edge >
  class DynamicGraph {

    using Edges = std::vector< Edge >;

   protected:
    std::vector< Edges > g;
    usize edge_count;

   public:
    using cost_type = typename Edge::cost_type;

    DynamicGraph() = default;
    explicit DynamicGraph(usize n) : g(n), edge_count(0) {}

    usize size() const {
      return g.size();
    }

    void add_directed_edge(usize from, usize to, cost_type cost = 1) {
      g[from].emplace_back(from, to, cost, edge_count++);
    }

    void add_undirected_edge(usize u, usize v, cost_type cost = 1) {
      assert(u != v);
      g[u].emplace_back(u, v, cost, edge_count);
      g[v].emplace_back(v, u, cost, edge_count++);
    }

    Edges operator[](const usize &v) {
      return g[v];
    }

    const Edges operator[](const usize &v) const {
      return g[v];
    }
  };

}

namespace luz {

  template< class G >
  class StronglyConnectedComponents {
    using graph = G;
    using cost_type = typename graph::cost_type;

    using groups_type = std::vector< std::vector< usize > >;

    graph g;
    usize n;

    std::vector< usize > low, ord, visited, group_id;

    usize ord_cnt, group_cnt;

    void dfs(usize v) {
      low[v] = ord[v] = ord_cnt++;
      visited.emplace_back(v);

      for (auto &e: g[v]) {
        if (ord[e.to] == n) {
          dfs(e.to);
          low[v] = std::min(low[v], low[e.to]);
        } else {
          low[v] = std::min(low[v], ord[e.to]);
        }
      }

      if (low[v] != ord[v]) return;

      while (true) {
        usize u = visited.back();
        visited.pop_back();

        ord[u] = n + 1;
        group_id[u] = group_cnt;

        if (u == v) break;
      }

      group_cnt++;
    }

   public:
    explicit StronglyConnectedComponents(const graph &g_) :
      g(g_),
      n(g.size()),
      low(n),
      ord(n, n),
      group_id(n),
      ord_cnt(0),
      group_cnt(0) {
        visited.reserve(n);

        for (usize v = 0; v < n; v++) {
          if (ord[v] != n) continue;
          dfs(v);
        }

        for (auto &id: group_id) {
          id = group_cnt - id - 1;
        }
      }

    groups_type groups() const {
      std::vector< usize > counts(group_cnt);
      for (usize i = 0; i < n; i++) {
        counts[group_id[i]]++;
      }

      groups_type groups(group_cnt);
      for (usize i = 0; i < group_cnt; i++) {
        groups[i].reserve(counts[i]);
      }

      for (usize i = 0; i < n; i++) {
        groups[group_id[i]].emplace_back(i);
      }

      return groups;
    }

    std::vector< usize > group_ids() const {
      return group_id;
    }
  };

}

using namespace luz;

using ll = long long;

bool func(){
  int n;
  int m;
  cin >> n >> m;
  vector<ll> as(n);
  for(auto &i:as)cin >> i;
  DynamicGraph<Edge<int>> graph(m);
  for(int i=0;i<m;++i){
    set<int> used;
    for(auto a:as){
      int v = (i * a) % m;
      if(used.count(v))continue;
      used.emplace(v);
      graph.add_directed_edge(i,v);
    }
  }

  StronglyConnectedComponents<DynamicGraph<Edge<int>>> scc(graph);

  vector<vector<long unsigned int>> groups = scc.groups();

  map<int,int> t;
  for(int i=0;i<groups.size();++i){
    for(auto j:groups[i]){
      t[j] = i;
    }
  }

  map<int,set<int>> child;

  for(int i=0;i<m;++i){
    int pi = t[i];
    for(auto a:as){
      int j = (i * a) % m;
      int pj = t[j];
      child[pi].emplace(pj);
    }
  }

  map<int,int> has_child;
  function<int(int)> rec = [&](int p) -> int{
    if(has_child.count(p))return has_child[p];
    int res = 0;
    for(auto i:child[p]){
      if(i == p)continue;
      res = max(res, rec(i) + 1);
    }
    return has_child[p] = res;
  };

  if(groups.size() != rec(t[1]) + 1)return false;

  int p = t[1];

  while(t[0] != p){
    bool ok = false;
    for(auto e:child[p]){
      if(rec(e) + 1 == rec(p)){
        ok = true;
        p = e;
        break;
      }
    }
    if(not ok)return false;
  }

  return true;
}

int main(){
  cout << (func() ? "Yes" : "No") << endl;
}
accuracy: 1
time_ms: 750
memory_kb: 179432
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

vector<int> SCC(const vector<vector<int>>& G) {
    int N = (int)G.size();
    vector<int> ord;
    vector<bool> vis(N);
    
    auto dfs1 = [&](auto dfs, int v) -> void {
        vis[v] = true;
        for (auto x : G[v])
            if (!vis[x]) dfs(dfs, x);
        ord.push_back(v);
    };

    for (int i = 0 ; i < N ; i++)
        if (!vis[i]) dfs1(dfs1, i);
    reverse(ord.begin(), ord.end());

    vector<vector<int>> G2(N);
    for (int i = 0 ; i < N ; i++) 
        for (auto t : G[i]) G2[t].push_back(i);

    vector<int> res(N, -1);
    int id = 0;
    auto dfs2 = [&](auto dfs, int v) -> void {
        res[v] = id;
        for (auto x : G2[v]) 
            if (res[x] == -1) dfs(dfs, x);
    };

    for (auto o : ord)
        if (res[o] == -1) {
            dfs2(dfs2, o);
            id++;
        }

    return res;
}

int main() {
    int N, M; cin >> N >> M;
    vector<ll> A(N);
    for (auto& a : A) cin >> a;

    vector<vector<int>> G(M);
    for (ll i = 0 ; i < M ; i++) {
        for (ll j = 0 ; j < N ; j++) {
            G[i].push_back((i * A[j]) % M);
        }
    }

    vector<int> scc = SCC(G);
    int size = *max_element(scc.begin(), scc.end()) + 1;
    
    vector<vector<int>> G2(size);
    for (int i = 0 ; i < M ; i++) {
        for (auto x : G[i]) {
            if (scc[i] == scc[x]) continue;
            G2[scc[i]].push_back(scc[x]);
        }
    }

    vector<int> memo(size, -1);
    auto dfs = [&](auto dfs, int v) -> int {
        if (memo[v] != -1) return memo[v];
        int res = 0;
        for (auto x : G2[v]) {
            res = max(res, dfs(dfs, x) + 1);
        }
        return memo[v] = res;
    };

    int len = dfs(dfs, scc[1]);
    bool ok = len == size - 1;

    if (ok) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}
accuracy: 1
time_ms: 60
memory_kb: 42576
final_rank: 5

code_snippet: #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=9167167167167167167;
const int INF=100000000;
const ll mod=998244353;
#define rep(i,a) for (int i=0;i<a;i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}
template<class T> void vec_out(vector<T> &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}

// return val=p(N)
// a=p[0].first^p[0].second * ... *p[N-1].first^p[N-1].second
// for all i: p[i].first is prime number
// O(sqrt(val))
std::vector<std::pair<long long,long long>> Prime_factorization(long long val){
	assert(val>=1);
	if(val==1){
		return {};
	}
	int ind=0;
	std::vector<std::pair<long long,long long>> ans;
	for(long long i=2;i*i<=val;i++){
		if(val%i!=0) continue;
		ans.push_back({i,0});
		while(val%i==0){
			ans[ind].second++;
			val/=i;
		}
		ind++;
	}
	if(val!=1) ans.push_back({val,1});
	return ans;
}
 

void solve();
// oddloop
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t=1;
	//cin>>t;
	rep(i,t) solve();
}

void solve(){
	int N,M;
	cin>>N>>M;
	vector<int> A(N);
	vector<bool> p(M);
	rep(i,N) cin>>A[i],A[i]%=M;
	vector<int> order={1};
	p[1]=1;
	int ind=0;
	while(ind!=(int)(order.size())){
		int a=order[ind];
		ind++;
		rep(i,N){
			int b=(a*A[i])%M;
			if(!p[b]){
				p[b]=1;
				order.push_back(b);
			}
		}
	}
	yneos(ind==M&&(int)(Prime_factorization(M).size())==1);
}
accuracy: 1
time_ms: 10
memory_kb: 3452
final_rank: 1

code_snippet: //#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
constexpr lint mod = 1e9 + 7;
#define all(x) begin(x), end(x)
#define bitcount(n) __builtin_popcountll((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzll(x))
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define rep2(i, l, r) for(int i = int(l); i < int(r); i++)
#define repr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define repr2(i, l, r) for(int i = int(r) - 1; i >= int(l); i--)
constexpr int inf9 = 1e9; constexpr lint inf18 = 1e18;
inline void Yes(bool condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class itr> void array_output(itr start, itr goal){ for(auto i = start; i != goal; i++) cout << (i == start ? "" : " ") << (*i); cout << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(b) return gcd(b, a % b); else return a; }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b){ if(b < a){ a = b; return 1; } return 0; }
inline int has(lint i, int j){ return (i >> j) & 1; }
int dy[4] = {1, 0, -1, 0}; int dx[4] = {0, 1, 0, -1};
bool is_inside(lint y, lint x, lint H, lint W){ return (0 <= y && y < H && 0 <= x && x < W); }

struct io_init {
    io_init() {
        cin.tie(nullptr); cout.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }
} io_init;

//using ushort = short;
using sint = int;

#define int short

template<class T = int>
struct Edge{
    int from, to;
    T cost;
    int id;
    
    Edge() = default;
    Edge(int from, int to, T cost = 1, int id = -1) : from(from), to(to), cost(cost), id(id) {}
    
    operator int() const { return to; }
};

template<class T = int>
struct Graph{
private:
    vector<vector<Edge<T>>> g;
public:
    sint edge_cnt = 0;
    T INF = numeric_limits<T>::max() / 4;
    
    Graph() = default;
    
    explicit Graph(int n) : g(n) {}
    
    int size(){
        return int(g.size());
    }
    
    void add_directed_edge(int from, int to, T cost = 1){
        g[from].push_back(Edge(from, to, cost, edge_cnt++));
    }
    
    void add_edge(int from, int to, T cost = 1){
        g[from].push_back(Edge(from, to, cost, edge_cnt));
        g[to].push_back(Edge(to, from, cost, edge_cnt++));
    }
    
    vector<Edge<T>>& operator [](int k){
        return g[k];
    }
    
    void resize(int n){
        g.resize(n);
    }
};
template<class T = int>
using Edges = vector<Edge<T>>;


template<class T = int>
struct SCC{
    Graph<T> graph, rev;

    int id;
    vector<int> id_inv;
    vector<bool> used;
    
    vector<int> comp;
//    vector<vector<int>> groups;
    Graph<T> dag;

    void dfs(int at){
        used[at] = true;
        for(int to: graph[at]){
            if(used[to]) continue;
            dfs(to);
        }
        id_inv[id] = at;
        id++;
    }
    
    int group_id;
    
    void dfs2(int at){
        comp[at] = group_id;
//        groups.back().push_back(at);
        used[at] = true;
        for(int to: rev[at]){
            if(used[to]) continue;
            dfs2(to);
        }
    }

    SCC(Graph<T> g): graph(g){
        int n = int(graph.size());
        
        rev = Graph<T>(n);
        rep(i, n){
            for(auto j: graph[i]){
                rev.add_directed_edge(j, i);
            }
        }
        
        id_inv.assign(n, -1);
        used.assign(n, false);
        id = 0;
        rep(i, n){
            if(used[i]) continue;
            dfs(i);
        }
        
        used.assign(n, false);
        comp.assign(n, -1);
        group_id = 0;
        repr(i, n){
            int v = id_inv[i];
            if(used[v]) continue;
//            groups.push_back({});
            dfs2(v);
            group_id++;
        }
        
        dag = Graph<T>(group_id);
        rep(i, n){
            for(auto e: graph[i]){
                if(comp[i] != comp[e.to]){
                    dag.add_directed_edge(comp[i], comp[e.to], e.cost);
                }
            }
        }
    }
};

signed main(){
    int n, m;
    cin >> n >> m;
    Graph g(m);
    rep(_, n){
        sint a;
        cin >> a;
        a %= m;
        rep(i, m){
            g.add_directed_edge(i, (i * a) % m);
        }
    }
    
    SCC<> scc(g);
    
    if(scc.comp[1] != 0){
        cout << "No" << endl;
        return 0;
    }
    
    int sz = int(scc.group_id);
    rep(i, sz - 1){
        bool is_ok = false;
        for(int to: scc.dag[i]){
            if(to == i + 1){
                is_ok = true;
                break;
            }
        }
        if(!is_ok){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}
accuracy: 1
time_ms: 150
memory_kb: 163260
final_rank: 17

code_snippet: #pragma region mytemplates

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

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL,LL> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
template<typename T> using prque = priority_queue<T,vector<T>>;
template<typename T> using prquer = priority_queue<T,vector<T>,greater<T>>;
#define umap unordered_map
#define uset unordered_set
#define umset unordered_multiset

#define LB lower_bound
#define UB upper_bound
#define FI first
#define SE second
#define EF emplace_front
#define EB emplace_back
#define PF push_front
#define PB push_back
#define POF pop_front
#define POB pop_back
#define MP make_pair
#define MT make_tuple
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SZ(a) (int)((a).size())
#define EXIST(s,e) (find((s).begin(),(s).end(),(e))!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).rbegin(), (c).rend())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define AAI(a,b,c) (a).begin(),(a).end(), (b).begin(),(b).end(), inserter(c,(c).end())
#define UNIQUE(v) (v).erase(unique((v).begin(),(v).end()), (v).end())

#define OVERLOAD4(a,b,c,d,name,...) name

#define FOR(i,a,b) for(auto i = decltype(b){a}, i##_r=(b); i<i##_r; i++)
#define REP(i,n) FOR(i,0,n)
#define FORR(i,a,b) for(auto i=decltype(b){b-1}, i##_l=(a); i>=i##_l; i--)
#define REPR(i,n) FORR(i,0,n)
#define CFOR(i,a,b) for(auto i = decltype(b){a}, i##_r=(b); i<=i##_r; i++)
#define CREP(i,n) CFOR(i,0,n)
#define SREP(i,n) CFOR(i,1,n)
#define CFORR(i,a,b) for(auto i=decltype(b){b}, i##_l=(a); i>=i##_l; i--)
#define CREPR(i,n) CFORR(i,0,n)
#define SREPR(i,n) CFORR(i,1,n)
#define BFOR(bit,a,b) for(LL bit=(a); bit<(1ll<<(b)); bit++)
#define BREP(bit,n) BFOR(bit,0,n)

#define EACH1(a, v) for(auto&&a : v)
#define EACH2(a,b, v) for(auto&&[a,b] : v)
#define EACH3(a,b,c, v) for(auto&&[a,b,c] : v)
#define EACH(...) OVERLOAD4(__VA_ARGS__, EACH3, EACH2, EACH1)(__VA_ARGS__)

#define elif else if
#define unless(a) if(!(a))

constexpr double EPS = 1e-10;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr LL LINF = numeric_limits<LL>::max()/3;
constexpr LL MOD = 1e9+7;
constexpr LL MODD = 998244353;
constexpr int MAX = 510000;
constexpr LL TEN(int n) { return n? 10*TEN(n-1) : 1; };

#define ADD_OVERFLOW(a, b) __builtin_add_overflow_p (a, b, (decltype((a)+(b))) 0)
#define SUB_OVERFLOW(a, b) __builtin_sub_overflow_p (a, b, (decltype((a)+(b))) 0)
#define MUL_OVERFLOW(a, b) __builtin_mul_overflow_p (a, b, (decltype((a)+(b))) 0)

template<class T> inline T sqr(T x) { return x*x; }
inline bool Eq(double a, double b) { return fabs(b - a) < EPS; }
template<class T> inline T CEIL(T x, T y) { return (x+y-1)/y; }
inline int popcnt(uint64_t x) { return __builtin_popcountll(x); }
template<typename T>
T ModInv(T a, T m){
  T b = m, u= 1, v = 0;
  while(b){
    T t = a/b;
    a -= t*b; swap(a,b);
    u -= t*v; swap(u,v);
  }
  u %= m; if(u<0) u+= m;
  return u;
}
template<typename T>
T mypow(T a, LL n, T m = 0, T e = 1){
  if(n < 0){ assert(m != 0); return ModInv(mypow(a, -n, m, e), m); }
  T res = e;
  while(n > 0){ if(n&1){ res *= a; if(m) res %= m; } a *= a; n >>= 1; if(m) a %= m; }
  return res;
}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename T>
T sum(const vector<T> &v){ return reduce(v.begin(), v.end()); }
template<typename T>
T gcd(const vector<T> &v){ return reduce(v.begin(), v.end(), T(0), [](auto&&a, auto&&b){ return gcd(a,b); }); }
template<typename T>
T lcm(const vector<T> &v){ return reduce(v.begin(), v.end(), T(1), [](auto&&a, auto&&b){ return lcm(a,b); }); }

template<typename T> T max(const vector<T> &v){return *max_element(v.begin(), v.end()); }
template<typename T> T min(const vector<T> &v){return *min_element(v.begin(), v.end()); }
template<typename T> void Vadd(vector<T> &v, T a){for(auto&& x : v) x += a; }

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...)); }

template<typename T>
valarray<T> make_va(size_t a,T b){return valarray(b,a);}
template<typename... Ts>
auto make_va(size_t a,Ts... ts){ return valarray(make_va(ts...), a); }

template<typename T>
vector<tuple<T>> in_zip(vector<T> &v){
  vector<tuple<T>> vt(v.size());
  for(size_t i = 0; i < v.size(); i++) vt[i] = make_tuple(v[i]);
  return vt;
}

template<typename T, typename... Ts>
auto in_zip(vector<T> &v, Ts&&... vs){
  auto vt = in_zip(v); auto vts = in_zip(vs...);
  vector res(v.size(), tuple_cat(vt[0], vts[0]));
  for(size_t i = 1; i < v.size(); i++) res[i] = tuple_cat(vt[i], vts[i]);
  return res;
}

template<typename T>
vector<tuple<int, T>> in_enumerate(vector<T> &v){
  vector<int> idx(v.size()); iota(idx.begin(), idx.end(), 0);
  return in_zip(idx, v);
}

template<typename T, typename... Ts>
auto in_enumerate(vector<T> &v, Ts&&... vs){
  vector<int> idx(v.size()); iota(idx.begin(), idx.end(), 0);
  return in_zip(idx, v, vs...);
}

bool cYN(bool fl=true,bool fl2=false){cout << (fl?"Yes":"No") << '\n'; if(fl2){ exit(0); } return fl; }
bool CYN(bool fl=true,bool fl2=false){cout << (fl?"YES":"NO") << '\n'; if(fl2){ exit(0); } return fl; }
template<typename T = int>
void error(T t=-1,bool fl=true){cout << t << '\n'; if(fl){ exit(0); } }
template<class T> void COUT(T&& t){ cout << t << '\n'; }
template<class T,class... Ts>
void COUT(T&& t,Ts&&... ts){ cout << t << " "; COUT(ts...); }
template<class... Ts> void CIN(Ts&&... ts){ (cin >> ... >> ts); }

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second; return is;
}
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << p.first << " " << p.second; return os;
}
template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(auto&&in : v) is >> in;
  return is;
}
template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < SZ(v); i++) os << v[i] << (i + 1 != SZ(v) ? " " : "");
  return os;
}

void Vcin([[maybe_unused]] size_t i) {}
template<class T, class... Ts>
void Vcin(size_t i, vector<T> &v, Ts&&... vs){ cin >> v[i]; Vcin(i, vs...); }
template<class T, class... Ts>
void Vcin(vector<T> &v,Ts&&... vs){ for(size_t i = 0; i < v.size(); i++) Vcin(i, v, vs...); }

template< typename T >
void Vcout(const vector<T> &v, const string &sep = "\n", const string &en = "\n"){
  for(size_t i = 0; i < v.size(); i++) cout << v[i] << (i+1 != v.size() ? sep : en);
}

constexpr int dx[] = {1,0,-1,0,1,1,-1,-1}, dy[] = {0,1,0,-1,1,-1,1,-1};

#define INPUT(T, ...) T __VA_ARGS__; CIN(__VA_ARGS__)

#ifdef _DEBUG
template<typename T> void debug_out(T &&t) { cout << t << "\n"; }
template <typename T, typename... Ts>
void debug_out(T&& t, Ts&&... ts){ cout << t << ", "; debug_out(ts...); }
#define dbg(...) do{ cout <<"L: "<<__LINE__<<" [ " << #__VA_ARGS__ << " ]: "; debug_out(__VA_ARGS__); } while(false)
#else
#define dbg(...)
#endif

#pragma endregion

struct StronglyConnectedComponents{
  int N;
  vector<vector<int>> G, rG;

  int group;
  vector<int> compo, order;
  vector<bool> used;

  template<typename T>
  StronglyConnectedComponents(const T &g, bool cal = true):N(g.size()), G(N), rG(N){
    for(int i = 0; i < N; i++){
      for(auto&&e : g[i]){
        G[i].emplace_back(e.to);
        rG[e.to].emplace_back(i);
      }
    }
    if(cal) build();
  }
  StronglyConnectedComponents(int n):N(n), G(n), rG(n){}

  int at(int k){return compo.at(k);}

  void addEdge(int u, int v){
    G[u].emplace_back(v);
    rG[v].emplace_back(u);
  }

  void build(){
    compo.assign(N,-1);
    used.assign(N,false);
    order.clear(); order.reserve(N);
    group = 0;

    for(int i = 0; i < N; i++) dfs(i);
    reverse(order.begin(), order.end());
    for(auto&&e : order){
      if(compo.at(e) == -1){
        rdfs(e,group);
        group++;
      }
    }
  }

  bool issame(int u, int v){
    return compo.at(u) == compo.at(v);
  }

  vector<vector<int>> reconstruct(){
    vector<vector<int>> ret(group);
    for(int i = 0; i < N; i++){
      for(auto to : G.at(i)){
        int s = compo.at(i);
        int t = compo.at(to);
        if(s != t) ret.at(s).emplace_back(t);
      }
    }
    for(auto&&v : ret){
      sort(v.begin(), v.end());
      v.erase(unique(v.begin(), v.end()), v.end());
    }
    return ret;
  }

  vector<vector<int>> groups(){
    vector<vector<int>> res(group);
    for(int i = 0; i < N; i++){
      int p = compo.at(i);
      res.at(p).emplace_back(i);
    }
    return res;
  }

private:
  void dfs(int now){
    if(used[now]) return;

    stack<pair<int, bool>> st;
    st.emplace(now, true);

    while(!st.empty()){
      auto[v,f] = st.top(); st.pop();
      if(f){
        if(used[v]) continue;
        used[v] = true;

        st.emplace(v, false);
        for(auto&&e : G[v]){
          if(used[e]) continue;
          st.emplace(e, true);
        }
      }else{
        order.emplace_back(v);
      }
    }
  }

  void rdfs(int now, int cnt){
    if(compo.at(now) != -1) return;
    compo.at(now) = cnt;

    stack<int> st; st.push(now);
    while(!st.empty()){
      auto v = st.top(); st.pop();

      for(auto&&e : rG[v]){
        if(compo[e] != -1) continue;
        compo[e] = cnt;
        st.push(e);
      }
    }
  }
};


int main(){
  // cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N, M; CIN(N, M);
  StronglyConnectedComponents scc(M);

  REP(i,N){
    int a; CIN(a); a %= M;
    REP(x,M){
      scc.addEdge(x, x*a%M);
    }
  }

  scc.build();

  auto dag = scc.reconstruct();
  auto s = scc.at(1);
  int k = SZ(dag);
  auto dp = make_v(k, 0);
  dp[s] = 1;

  REP(i,k)if(dp[i]){
    EACH(e, dag[i]){
      chmax(dp[e], dp[i]+1);
    }
  }

  cYN(max(dp) == k);

  return 0;
}
accuracy: 1
time_ms: 160
memory_kb: 53012
final_rank: 8

code_snippet: #line 2 "/home/yuruhiya/programming/library/template/template.cpp"
#include <bits/stdc++.h>
#line 4 "/home/yuruhiya/programming/library/template/constants.cpp"
#include <string_view>
#line 7 "/home/yuruhiya/programming/library/template/constants.cpp"

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rfor(i, m, n) for (int i = (m); i >= (n); --i)
#define unless(c) if (!(c))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define range_it(a, l, r) (a).begin() + (l), (a).begin() + (r)

using namespace std;
using ll = long long;
using LD = long double;
using VB = vector<bool>;
using VVB = vector<VB>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VS = vector<string>;
using VD = vector<LD>;
using PII = pair<int, int>;
using VP = vector<PII>;
using PLL = pair<ll, ll>;
using VPL = vector<PLL>;
template <class T> using PQ = priority_queue<T>;
template <class T> using PQS = priority_queue<T, vector<T>, greater<T>>;
constexpr int inf = 1000000000;
constexpr long long inf_ll = 1000000000000000000ll, MOD = 1000000007;
constexpr long double PI = 3.14159265358979323846, EPS = 1e-12;
namespace CharacterClass {
	constexpr string_view
	    digit = "0123456789",
	    xdigit = "0123456789ABCDEFabcdef", lower = "abcdefghijklmnopqrstuvwxyz",
	    upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
	    alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
	    alnum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
	    word = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz",
	    punct = R"(!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~)",
	    graph =
	        R"(!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~)",
	    print =
	        R"( !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~)",
	    blank = " \t", space = " \t\n\r\f\v";
}  // namespace CharacterClass
#line 7 "/home/yuruhiya/programming/library/template/Input.cpp"
using namespace std;

#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock
#define fwrite_unlocked fwrite
#define fflush_unlocked fflush
#endif
class Scanner {
	static int gc() {
		return getchar_unlocked();
	}
	static char next_char() {
		char c;
		read(c);
		return c;
	}
	template <class T> static void read(T& v) {
		cin >> v;
	}
	static void read(char& v) {
		while (isspace(v = gc()))
			;
	}
	static void read(bool& v) {
		v = next_char() != '0';
	}
	static void read(string& v) {
		v.clear();
		for (char c = next_char(); !isspace(c); c = gc()) v += c;
	}
	static void read(int& v) {
		v = 0;
		bool neg = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; isdigit(c); c = gc()) v = v * 10 + (c - '0');
		if (neg) v = -v;
	}
	static void read(long long& v) {
		v = 0;
		bool neg = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; isdigit(c); c = gc()) v = v * 10 + (c - '0');
		if (neg) v = -v;
	}
	static void read(double& v) {
		v = 0;
		double dp = 1;
		bool neg = false, after_dp = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; isdigit(c) || c == '.'; c = gc()) {
			if (c == '.') {
				after_dp = true;
			} else if (after_dp) {
				v += (c - '0') * (dp *= 0.1);
			} else {
				v = v * 10 + (c - '0');
			}
		}
		if (neg) v = -v;
	}
	static void read(long double& v) {
		v = 0;
		long double dp = 1;
		bool neg = false, after_dp = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; isdigit(c) || c == '.'; c = gc()) {
			if (c == '.') {
				after_dp = true;
			} else if (after_dp) {
				v += (c - '0') * (dp *= 0.1);
			} else {
				v = v * 10 + (c - '0');
			}
		}
		if (neg) v = -v;
	}
	template <class T, class U> static void read(pair<T, U>& v) {
		read(v.first);
		read(v.second);
	}
	template <class T> static void read(vector<T>& v) {
		for (auto& e : v) read(e);
	}
	template <size_t N = 0, class T> static void read_tuple_impl(T& v) {
		if constexpr (N < tuple_size_v<T>) {
			read(get<N>(v));
			read_tuple_impl<N + 1>(v);
		}
	}
	template <class... T> static void read(tuple<T...>& v) {
		read_tuple_impl(v);
	}
	struct ReadVectorHelper {
		size_t n;
		ReadVectorHelper(size_t _n) : n(_n) {}
		template <class T> operator vector<T>() {
			vector<T> v(n);
			read(v);
			return v;
		}
	};
	struct Read2DVectorHelper {
		size_t n, m;
		Read2DVectorHelper(const pair<size_t, size_t>& nm) : n(nm.first), m(nm.second) {}
		template <class T> operator vector<vector<T>>() {
			vector<vector<T>> v(n, vector<T>(m));
			read(v);
			return v;
		}
	};

public:
	string read_line() const {
		string v;
		for (char c = gc(); c != '\n' && c != '\0'; c = gc()) v += c;
		return v;
	}
	template <class T> T read() const {
		T v;
		read(v);
		return v;
	}
	template <class T> vector<T> read_vector(size_t n) const {
		vector<T> a(n);
		read(a);
		return a;
	}
	template <class T> operator T() const {
		return read<T>();
	}
	int operator--(int) const {
		return read<int>() - 1;
	}
	ReadVectorHelper operator[](size_t n) const {
		return ReadVectorHelper(n);
	}
	Read2DVectorHelper operator[](const pair<size_t, size_t>& nm) const {
		return Read2DVectorHelper(nm);
	}
	void operator()() const {}
	template <class H, class... T> void operator()(H&& h, T&&... t) const {
		read(h);
		operator()(forward<T>(t)...);
	}

private:
	template <template <class...> class, class...> struct Multiple;
	template <template <class...> class V, class Head, class... Tail>
	struct Multiple<V, Head, Tail...> {
		template <class... Args> using vec = V<vector<Head>, Args...>;
		using type = typename Multiple<vec, Tail...>::type;
	};
	template <template <class...> class V> struct Multiple<V> { using type = V<>; };
	template <class... T> using multiple_t = typename Multiple<tuple, T...>::type;
	template <size_t N = 0, class T> void multiple_impl(T& t) const {
		if constexpr (N < tuple_size_v<T>) {
			auto& vec = get<N>(t);
			using V = typename remove_reference_t<decltype(vec)>::value_type;
			vec.push_back(read<V>());
			multiple_impl<N + 1>(t);
		}
	}

public:
	template <class... T> auto multiple(size_t h) const {
		multiple_t<T...> result;
		while (h--) multiple_impl(result);
		return result;
	}
} in;
#define inputs(T, ...) \
	T __VA_ARGS__;     \
	in(__VA_ARGS__)
#define ini(...) inputs(int, __VA_ARGS__)
#define inl(...) inputs(long long, __VA_ARGS__)
#define ins(...) inputs(string, __VA_ARGS__)
#line 7 "/home/yuruhiya/programming/library/template/Output.cpp"
#include <charconv>
#line 10 "/home/yuruhiya/programming/library/template/Output.cpp"
using namespace std;

struct BoolStr {
	const char *t, *f;
	BoolStr(const char* _t, const char* _f) : t(_t), f(_f) {}
} Yes("Yes", "No"), yes("yes", "no"), YES("YES", "NO"), Int("1", "0");
struct DivStr {
	const char *d, *l;
	DivStr(const char* _d, const char* _l) : d(_d), l(_l) {}
} spc(" ", "\n"), no_spc("", "\n"), end_line("\n", "\n"), comma(",", "\n"),
    no_endl(" ", "");
class Printer {
	BoolStr B{Yes};
	DivStr D{spc};

public:
	void print(int v) const {
		char buf[12]{};
		if (auto [ptr, e] = to_chars(begin(buf), end(buf), v); e == errc{}) {
			fwrite(buf, sizeof(char), ptr - buf, stdout);
		} else {
			assert(false);
		}
	}
	void print(long long v) const {
		char buf[21]{};
		if (auto [ptr, e] = to_chars(begin(buf), end(buf), v); e == errc{}) {
			fwrite(buf, sizeof(char), ptr - buf, stdout);
		} else {
			assert(false);
		}
	}
	void print(bool v) const {
		print(v ? B.t : B.f);
	}
	void print(vector<bool>::reference v) const {
		print(v ? B.t : B.f);
	}
	void print(char v) const {
		putchar_unlocked(v);
	}
	void print(const char* v) const {
		fwrite_unlocked(v, 1, strlen(v), stdout);
	}
	void print(double v) const {
		printf("%.20f", v);
	}
	void print(long double v) const {
		printf("%.20Lf", v);
	}
	template <class T> void print(const T& v) const {
		cout << v;
	}
	template <class T, class U> void print(const pair<T, U>& v) const {
		print(v.first);
		print(D.d);
		print(v.second);
	}
	template <class InputIterater>
	void print_range(const InputIterater& begin, const InputIterater& end) const {
		for (InputIterater i = begin; i != end; ++i) {
			if (i != begin) print(D.d);
			print(*i);
		}
	}
	template <class T> void print(const vector<T>& v) const {
		print_range(v.begin(), v.end());
	}
	template <class T, size_t N> void print(const array<T, N>& v) const {
		print_range(v.begin(), v.end());
	}
	template <class T> void print(const vector<vector<T>>& v) const {
		for (size_t i = 0; i < v.size(); ++i) {
			if (i) print(D.l);
			print(v[i]);
		}
	}

	Printer() = default;
	Printer(const BoolStr& _boolstr, const DivStr& _divstr) : B(_boolstr), D(_divstr) {}
	Printer& operator()() {
		print(D.l);
		return *this;
	}
	template <class H> Printer& operator()(H&& h) {
		print(h);
		print(D.l);
		return *this;
	}
	template <class H, class... T> Printer& operator()(H&& h, T&&... t) {
		print(h);
		print(D.d);
		return operator()(forward<T>(t)...);
	}
	template <class InputIterator>
	Printer& range(const InputIterator& begin, const InputIterator& end) {
		print_range(begin, end);
		print(D.l);
		return *this;
	}
	template <class T> Printer& range(const T& a) {
		range(a.begin(), a.end());
		return *this;
	}
	template <class... T> void exit(T&&... t) {
		operator()(forward<T>(t)...);
		std::exit(EXIT_SUCCESS);
	}
	Printer& flush() {
		fflush_unlocked(stdout);
		return *this;
	}
	Printer& set(const BoolStr& b) {
		B = b;
		return *this;
	}
	Printer& set(const DivStr& d) {
		D = d;
		return *this;
	}
	Printer& set(const char* t, const char* f) {
		B = BoolStr(t, f);
		return *this;
	}
} out;
#line 3 "/home/yuruhiya/programming/library/template/Step.cpp"
using namespace std;

template <class T> struct Step {
	using value_type = T;

	class iterator {
		value_type a, b, c;

	public:
		constexpr iterator() : a(value_type()), b(value_type()), c(value_type()) {}
		constexpr iterator(value_type _b, value_type _c, value_type _s)
		    : a(_b), b(_c), c(_s) {}
		constexpr iterator& operator++() {
			--b;
			a += c;
			return *this;
		}
		constexpr iterator operator++(int) {
			iterator tmp = *this;
			--b;
			a += c;
			return tmp;
		}
		constexpr const value_type& operator*() const {
			return a;
		}
		constexpr const value_type* operator->() const {
			return &a;
		}
		constexpr bool operator==(const iterator& i) const {
			return b == i.b;
		}
		constexpr bool operator!=(const iterator& i) const {
			return !(b == i.b);
		}
		constexpr value_type start() const {
			return a;
		}
		constexpr value_type size() const {
			return b;
		}
		constexpr value_type step() const {
			return c;
		}
	};
	constexpr Step(value_type b, value_type c, value_type s) : be(b, c, s) {}
	constexpr iterator begin() const {
		return be;
	}
	constexpr iterator end() const {
		return en;
	}
	constexpr value_type start() const {
		return be.start();
	}
	constexpr value_type size() const {
		return be.size();
	}
	constexpr value_type step() const {
		return be.step();
	}
	constexpr value_type sum() const {
		return start() * size() + step() * (size() * (size() - 1) / 2);
	}
	operator vector<value_type>() const {
		return to_a();
	}
	auto to_a() const {
		vector<value_type> result;
		result.reserve(size());
		for (auto i : *this) {
			result.push_back(i);
		}
		return result;
	}

private:
	iterator be, en;
};
template <class T> constexpr auto step(T a) {
	return Step<T>(0, a, 1);
}
template <class T> constexpr auto step(T a, T b) {
	return Step<T>(a, b - a, 1);
}
template <class T> constexpr auto step(T a, T b, T c) {
	return Step<T>(a, a < b ? (b - a - 1) / c + 1 : 0, c);
}
#line 8 "/home/yuruhiya/programming/library/template/Ruby.cpp"
using namespace std;

template <class F> struct Callable {
	F func;
	Callable(const F& f) : func(f) {}
};
template <class T, class F> auto operator|(const T& v, const Callable<F>& c) {
	return c.func(v);
}

struct Sort_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			sort(begin(v), end(v), f);
			return v;
		});
	}
	template <class T> friend auto operator|(T v, [[maybe_unused]] const Sort_impl& c) {
		sort(begin(v), end(v));
		return v;
	}
} Sort;
struct SortBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			sort(begin(v), end(v),
			     [&](const auto& i, const auto& j) { return f(i) < f(j); });
			return v;
		});
	}
} SortBy;
struct RSort_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			sort(rbegin(v), rend(v), f);
			return v;
		});
	}
	template <class T> friend auto operator|(T v, [[maybe_unused]] const RSort_impl& c) {
		sort(rbegin(v), rend(v));
		return v;
	}
} RSort;
struct RSortBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			sort(begin(v), end(v),
			     [&](const auto& i, const auto& j) { return f(i) > f(j); });
			return v;
		});
	}
} RSortBy;
struct Reverse_impl {
	template <class T> friend auto operator|(T v, const Reverse_impl& c) {
		reverse(begin(v), end(v));
		return v;
	}
} Reverse;
struct Unique_impl {
	template <class T> friend auto operator|(T v, const Unique_impl& c) {
		v.erase(unique(begin(v), end(v), end(v)));
		return v;
	}
} Unique;
struct Uniq_impl {
	template <class T> friend auto operator|(T v, const Uniq_impl& c) {
		sort(begin(v), end(v));
		v.erase(unique(begin(v), end(v)), end(v));
		return v;
	}
} Uniq;
struct Rotate_impl {
	auto operator()(int&& left) {
		return Callable([&](auto v) {
			int s = static_cast<int>(size(v));
			assert(-s <= left && left <= s);
			if (0 <= left) {
				rotate(begin(v), begin(v) + left, end(v));
			} else {
				rotate(begin(v), end(v) + left, end(v));
			}
			return v;
		});
	}
} Rotate;
struct Max_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) { return *max_element(begin(v), end(v), f); });
	}
	template <class T> friend auto operator|(T v, const Max_impl& c) {
		return *max_element(begin(v), end(v));
	}
} Max;
struct Min_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) { return *min_element(begin(v), end(v), f); });
	}
	template <class T> friend auto operator|(T v, const Min_impl& c) {
		return *min_element(begin(v), end(v));
	}
} Min;
struct MaxPos_impl {
	template <class T> friend auto operator|(T v, const MaxPos_impl& c) {
		return max_element(begin(v), end(v)) - begin(v);
	}
} MaxPos;
struct MinPos_impl {
	template <class T> friend auto operator|(T v, const MinPos_impl& c) {
		return min_element(begin(v), end(v)) - begin(v);
	}
} MinPos;
struct MaxBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto max_it = begin(v);
			auto max_val = f(*max_it);
			for (auto it = next(begin(v)); it != end(v); ++it) {
				if (auto val = f(*it); max_val < val) {
					max_it = it;
					max_val = val;
				}
			}
			return *max_it;
		});
	}
} MaxBy;
struct MinBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto min_it = begin(v);
			auto min_val = f(*min_it);
			for (auto it = next(begin(v)); it != end(v); ++it) {
				if (auto val = f(*it); min_val > val) {
					min_it = it;
					min_val = val;
				}
			}
			return *min_it;
		});
	}
} MinBy;
struct MaxOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto max_val = f(*begin(v));
			for (auto it = next(begin(v)); it != end(v); ++it) {
				if (auto val = f(*it); max_val < val) {
					max_val = val;
				}
			}
			return max_val;
		});
	}
} MaxOf;
struct MinOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto min_val = f(*begin(v));
			for (auto it = next(begin(v)); it != end(v); ++it) {
				if (auto val = f(*it); min_val > val) {
					min_val = val;
				}
			}
			return min_val;
		});
	}
} MinOf;
struct Count_impl {
	template <class V> auto operator()(const V& val) {
		return Callable([&](auto v) { return count(begin(v), end(v), val); });
	}
} Count;
struct CountIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) { return count_if(begin(v), end(v), f); });
	}
} CountIf;
struct Index_impl {
	template <class V> auto operator()(const V& val) {
		return Callable([&](auto v) -> optional<int> {
			auto result = find(begin(v), end(v), val);
			return result != end(v) ? optional(result - begin(v)) : nullopt;
		});
	}
} Index;
struct IndexIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) -> optional<int> {
			auto result = find_if(begin(v), end(v), f);
			return result != end(v) ? optional(result - begin(v)) : nullopt;
		});
	}
} IndexIf;
struct FindIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) -> optional<typename decltype(v)::value_type> {
			auto result = find_if(begin(v), end(v), f);
			return result != end(v) ? optional(*result) : nullopt;
		});
	}
} FindIf;
struct Sum_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			return accumulate(next(begin(v)), end(v), f(*begin(v)),
			                  [&](const auto& a, const auto& b) { return a + f(b); });
		});
	}
	template <class T> friend auto operator|(T v, const Sum_impl& c) {
		return accumulate(begin(v), end(v), typename T::value_type{});
	}
} Sum;
struct Includes {
	template <class V> auto operator()(const V& val) {
		return Callable([&](auto v) { return find(begin(v), end(v), val) != end(v); });
	}
} Includes;
struct IncludesIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) { return find_if(begin(v), end(v), f) != end(v); });
	}
} IncludesIf;
struct RemoveIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) {
			v.erase(remove_if(begin(v), end(v), f), end(v));
			return v;
		});
	}
} RemoveIf;
struct Each_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				f(i);
			}
		});
	}
} Each;
struct Select_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			using value_type = typename decltype(v)::value_type;
			vector<value_type> result;
			for (const auto& i : v) {
				if (f(i)) result.push_back(i);
			}
			return result;
		});
	}
} Select;
struct Map_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			using result_type = invoke_result_t<F, typename decltype(v)::value_type>;
			vector<result_type> result;
			result.reserve(size(v));
			for (const auto& i : v) {
				result.push_back(f(i));
			}
			return result;
		});
	}
} Map;
struct Indexed_impl {
	template <class T> friend auto operator|(const T& v, Indexed_impl& c) {
		using value_type = typename T::value_type;
		vector<pair<value_type, int>> result;
		result.reserve(size(v));
		int index = 0;
		for (const auto& i : v) {
			result.emplace_back(i, index++);
		}
		return result;
	}
} Indexed;
struct AllOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				if (!f(i)) return false;
			}
			return true;
		});
	}
} AllOf;
struct AnyOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				if (f(i)) return true;
			}
			return false;
		});
	}
} AnyOf;
struct NoneOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				if (f(i)) return false;
			}
			return true;
		});
	}
} NoneOf;

struct Tally_impl {
	template <class F> auto operator()(size_t max_val) {
		return Callable([&](auto v) {
			vector<size_t> result(max_val);
			for (const auto& i : v) {
				result[static_cast<size_t>(i)]++;
			}
			return result;
		});
	}
	template <class T, class value_type = typename T::value_type>
	friend auto operator|(const T& v, Tally_impl& c) {
		map<value_type, size_t> result;
		for (const auto& i : v) {
			result[i]++;
		}
		return result;
	}
} Tally;

template <class T> auto operator*(const vector<T>& a, size_t n) {
	T result;
	for (size_t i = 0; i < n; ++i) {
		result.insert(result.end(), a.begin(), a.end());
	}
	return result;
}
auto operator*(string a, size_t n) {
	string result;
	for (size_t i = 0; i < n; ++i) {
		result += a;
	}
	return result;
}
template <class T, class U> auto& operator<<(vector<T>& a, const U& b) {
	a.insert(a.end(), all(b));
	return a;
}
template <class T> auto& operator<<(string& a, const T& b) {
	a.insert(a.end(), all(b));
	return a;
}
template <class T, class U> auto operator+(vector<T> a, const U& b) {
	a << b;
	return a;
}
template <class T> auto operator+(string a, const T& b) {
	a << b;
	return a;
}
#line 7 "/home/yuruhiya/programming/library/template/functions.cpp"
using namespace std;

template <class T = long long> constexpr T TEN(size_t n) {
	T result = 1;
	for (size_t i = 0; i < n; ++i) result *= 10;
	return result;
}
template <class T, class U,
          enable_if_t<is_integral_v<T> && is_integral_v<U>, nullptr_t> = nullptr>
constexpr auto div_ceil(T n, U m) {
	return (n + m - 1) / m;
}
template <class T, class U> constexpr auto div_ceil2(T n, U m) {
	return div_ceil(n, m) * m;
}
template <class T> constexpr T triangle(T n) {
	return (n & 1) ? (n + 1) / 2 * n : n / 2 * (n + 1);
}
template <class T> constexpr T nC2(T n) {
	return (n & 1) ? (n - 1) / 2 * n : n / 2 * (n - 1);
}
template <class T, class U> constexpr auto middle(const T& l, const U& r) {
	return l + (r - l) / 2;
}
template <class T, class U, class V>
constexpr bool in_range(const T& v, const U& lower, const V& upper) {
	return lower <= v && v < upper;
}
template <class T, enable_if_t<is_integral_v<T>, nullptr_t> = nullptr>
constexpr bool is_square(T n) {
	T s = sqrt(n);
	return s * s == n || (s + 1) * (s + 1) == n;
}
template <class T = long long> constexpr T BIT(int b) {
	return T(1) << b;
}
template <class T> constexpr int BIT(T x, int i) {
	return (x & (1 << i)) ? 1 : 0;
}
template <class T, class U, enable_if_t<is_integral_v<U>, nullptr_t> = nullptr>
constexpr T Pow(T a, U n) {
	assert(n >= 0);
	T result = 1;
	while (n > 0) {
		if (n & 1) {
			result *= a;
			n--;
		} else {
			a *= a;
			n >>= 1;
		}
	}
	return result;
}
template <class T, class U, enable_if_t<is_integral_v<U>, nullptr_t> = nullptr>
constexpr T Powmod(T a, U n, T mod) {
	assert(n >= 0);
	if (a > mod) a %= mod;
	T result = 1;
	while (n > 0) {
		if (n & 1) {
			result = result * a % mod;
			n--;
		} else {
			a = a * a % mod;
			n >>= 1;
		}
	}
	return result;
}
template <class T> bool chmax(T& a, const T& b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> bool chmin(T& a, const T& b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> int sz(const T& v) {
	return v.size();
}
template <class T, class U> int lower_index(const T& a, const U& v) {
	return lower_bound(all(a), v) - a.begin();
}
template <class T, class U> int upper_index(const T& a, const U& v) {
	return upper_bound(all(a), v) - a.begin();
}
template <class T> auto Slice(const T& v, size_t i, size_t len) {
	return i < v.size() ? T(v.begin() + i, v.begin() + min(i + len, v.size())) : T();
}
template <class T, class U = typename T::value_type> U Gcdv(const T& v) {
	return accumulate(next(v.begin()), v.end(), U(*v.begin()), gcd<U, U>);
}
template <class T, class U = typename T::value_type> U Lcmv(const T& v) {
	return accumulate(next(v.begin()), v.end(), U(*v.begin()), lcm<U, U>);
}
namespace internal {
	template <class T, size_t N> auto make_vector(vector<int>& sizes, const T& init) {
		if constexpr (N == 1) {
			return vector(sizes[0], init);
		} else {
			int size = sizes[N - 1];
			sizes.pop_back();
			return vector(size, make_vector<T, N - 1>(sizes, init));
		}
	}
}  // namespace internal
template <class T, size_t N>
auto make_vector(const int (&sizes)[N], const T& init = T()) {
	vector s(rbegin(sizes), rend(sizes));
	return internal::make_vector<T, N>(s, init);
}
#line 9 "/home/yuruhiya/programming/library/template/template.cpp"
#if __has_include(<library/dump.hpp>)
#include <library/dump.hpp>
#define LOCAL
#else
#define dump(...) ((void)0)
#endif

template <class T> constexpr T oj_local(const T& oj, const T& local) {
#ifndef LOCAL
	return oj;
#else
	return local;
#endif
}
#line 5 "/home/yuruhiya/programming/library/Graph/StronglyConnectedComponents.cpp"
using namespace std;

class StronglyConnectedComponents {
	int n;
	vector<vector<int>> graph, rgraph;
	vector<bool> used;
	vector<int> cmp, vs;
	int k;
	bool builded = false;
	void dfs(int v) {
		used[v] = true;
		for (auto e : graph[v]) {
			if (!used[e]) dfs(e);
		}
		vs.push_back(v);
	}
	void rdfs(int v, int k) {
		used[v] = true;
		cmp[v] = k;
		for (auto e : rgraph[v]) {
			if (!used[e]) rdfs(e, k);
		}
	}

public:
	StronglyConnectedComponents(int _n) : n(_n), graph(n), rgraph(n) {}
	StronglyConnectedComponents(const vector<vector<int>>& _graph)
	    : n(_graph.size()), graph(_graph), rgraph(n) {
		for (int v = 0; v < n; ++v) {
			for (int u : graph[v]) {
				rgraph[u].push_back(v);
			}
		}
	}
	void add_edge(int s, int t) {
		builded = false;
		graph[s].push_back(t);
		rgraph[t].push_back(s);
	}
	int build() {
		vs.clear();
		used.assign(n, false);
		cmp.assign(n, 0);
		for (int i = 0; i < n; ++i) {
			if (!used[i]) dfs(i);
		}
		k = 0;
		fill(used.begin(), used.end(), false);
		for (int i = vs.size() - 1; i >= 0; --i) {
			if (!used[vs[i]]) rdfs(vs[i], k++);
		}
		builded = true;
		return k;
	}
	int operator[](int i) const {
		assert(builded);
		return cmp[i];
	}
	const vector<int>& get_cmp() const {
		assert(builded);
		return cmp;
	}
	const vector<vector<int>>& get_graph() const {
		assert(builded);
		return graph;
	}
	int count_strongly_components() const {
		assert(builded);
		return k;
	}
	vector<vector<int>> groups() const {
		assert(builded);
		vector<vector<int>> result(k);
		for (int i = 0; i < n; ++i) {
			result[cmp[i]].push_back(i);
		}
		return result;
	}
	vector<vector<int>> make_DAG() const {
		assert(builded);
		vector<vector<int>> result(k);
		for (int i = 0; i < n; ++i) {
			for (auto e : graph[i]) {
				if (cmp[i] != cmp[e]) {
					result[cmp[i]].push_back(cmp[e]);
				}
			}
		}
		for (auto& v : result) {
			sort(v.begin(), v.end());
			v.erase(unique(v.begin(), v.end()), v.end());
		}
		return result;
	}
};
#line 3 "a.cpp"

int main() {
	ini(n, m);
	VL a = in[n];
	StronglyConnectedComponents scc(m);
	rep(x, m) {
		VB to(m);
		rep(i, n) {
			to[x * a[i] % m] = true;
		}
		rep(y, m) if (to[y]) {
			scc.add_edge(x, y);
		}
	}

	int k = scc.build();
	auto g = scc.make_DAG();
	VVI rg(k);
	rep(v, k) {
		for (int u : g[v]) {
			rg[u].push_back(v);
		}
	}
	dump(k, g, rg, scc.groups(), scc[1]);

	VI dp(k, -1);
	auto rec = [&](auto&& f, int v) -> int {
		int& res = dp[v];
		if (res != -1) return res;
		res = 1;
		for (int u : rg[v]) {
			chmax(res, f(f, u) + 1);
		}
		return res;
	};
	rep(i, k) rec(rec, i);
	out(dp | AnyOf([&](int i) { return i == k; }));
}
accuracy: 1
time_ms: 60
memory_kb: 29932
final_rank: 4

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define irep(i,a,b) for(int i=int(a);i<(int)b;++i)
#define rrep(i,a,b) for(int i=int(a);i>=(int)b;--i)
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvp vector<vector<pair<ll,ll>>>
#define vpl vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define pb push_back
#define se second
#define fi first
#define all(v) v.begin(),v.end()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>

using namespace std;

template<typename T> istream& operator>>(istream&i,v(T)&v){rep(j,v.size())i>>v[j];return i;}
template<typename T> string join(const v(T)&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T> ostream& operator<<(ostream&o,const v(T)&v){if(v.size())o<<join(v);return o;}



using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

const ll mod = 1e9 + 7; //998244353;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


ll modpow(ll a,ll b){
    if(b == 0){
        return 1;
    }
    if(b%2 == 0){
        ll tmp = modpow(a,b/2);
        return tmp*tmp%mod;
    }else{
        return modpow(a,b-1)*a%mod;
    }

}

struct SieveOfEratosthenes : std::vector<int>
{
    std::vector<int> primes;
    SieveOfEratosthenes(int MAXN) : std::vector<int>(MAXN + 1) {
        std::iota(this->begin(), this->end(), 0);
        for (int i = 2; i <= MAXN; i++) {
            if ((*this)[i] == i) {
                primes.push_back(i);
                for (int j = i; j <= MAXN; j += i) (*this)[j] = i;
            }
        }
    }
    using T = long long int;
    // Prime factorization for x <= MAXN^2
    // Complexity: O(log x)          (x <= MAXN)
    //             O(MAXN / logMAXN) (MAXN < x <= MAXN^2)
    std::map<T, int> Factorize(T x) {
        assert(x <= 1LL * (int(size()) - 1) * (int(size()) - 1));
        std::map<T, int> ret;
        if (x < int(size())) {
            while (x > 1) {
                ret[(*this)[x]]++;
                x /= (*this)[x];
            }
        }
        else {
            for (auto p : primes) {
                while (!(x % p)) x /= p, ret[p]++;
                if (x == 1) break;
            }
            if (x > 1) ret[x]++;
        }
        return ret;
    }
    std::vector<T> Divisors(T x) {
        std::vector<T> ret{1};
        for (auto p : Factorize(x)) {
            int n = ret.size();
            for (int i = 0; i < n; i++) {
                for (T a = 1, d = 1; d <= p.second; d++) {
                    a *= p.first;
                    ret.push_back(ret[i] * a);
                }
            }
        }
        return ret; // Not sorted
    }
    // Moebius function Table
    // return: [0=>0, 1=>1, 2=>-1, 3=>-1, 4=>0, 5=>-1, 6=>1, 7=>-1, 8=>0, ...]
    std::vector<int> GenerateMoebiusFunctionTable() {
        std::vector<int> ret(size());
        for (int i = 1; i < int(size()); i++) {
            if (i == 1) ret[i] = 1;
            else if ((i / (*this)[i]) % (*this)[i] == 0) ret[i] = 0;
            else ret[i] = -ret[i / (*this)[i]];
        }
        return ret;
    }
};
int n,m;




int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    cin >> n >> m;
    vl a(n);
    vector<bool>mods(m,false);
    SieveOfEratosthenes sieve(100000);
    auto fac = sieve.Factorize(m);
    if (fac.size() > 1)
    {
        cout << "No" << endl;
        return 0;
    }
    rep(i,n){
        cin >> a[i];
        a[i] %= m;
        mods[a[i]] = true;
    }
    rep(i,n){
        while(true){
            bool update = false;
            rep(j,m)if(mods[j] && !mods[j*a[i]%m]){
                update = true;
                mods[j*a[i]%m] = true;
            }
            if(!update)break;
        }
    }
    bool flag = true;
    rep(i,m)if(!mods[i])flag = false;

    cout << (flag ? "Yes" : "No") << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3768
final_rank: 2

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 9223372036854775807
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 2005

struct GROUP{
	vector<int> nodes;
};

GROUP group[NUM]; //強連結成分のグループ
vector<int> G[NUM],scc_G[NUM];
vector<int> reverse_G[NUM];
stack<int> S;

bool used[NUM][NUM],scc_used[NUM][NUM];
bool work[NUM],check[NUM];
int table[NUM],in_num[NUM],max_dist[NUM];
double sleep[NUM];

int group_index;

void dfs(int node_id){
	check[node_id] = true;

	for(int i = 0; i < G[node_id].size(); i++){
		if(!check[G[node_id][i]])dfs(G[node_id][i]);
	}
	S.push(node_id);
}

void reverse_dfs(int node_id){
	check[node_id] = true;

	group[group_index].nodes.push_back(node_id);
	table[node_id] = group_index;

	for(int i = 0; i < reverse_G[node_id].size(); i++){
		if(!check[reverse_G[node_id][i]])reverse_dfs(reverse_G[node_id][i]);
	}
}

int main(){

	int N,M;
	scanf("%d %d",&N,&M);

	for(int i = 0; i < M; i++){
		for(int k = 0; k < M; k++){

			used[i][k] = false;
			scc_used[i][k] = false;
		}
	}

	int tmp;
	vector<int> vec;

	for(int i = 0; i < N; i++){

		scanf("%d",&tmp);
		vec.push_back(tmp%M);
	}
	sort(vec.begin(),vec.end());
	vec.erase(unique(vec.begin(),vec.end()),vec.end());

	for(int i = 0; i < M; i++){

		work[i] = false;
	}
	for(int i = 0; i < vec.size(); i++){

		work[vec[i]] = true;
		G[1].push_back(vec[i]);
		used[1][vec[i]] = true;
		reverse_G[vec[i]].push_back(1);
	}
	check[1] = true;

	vector<int> NEW = vec;
	vector<int> ADD;

	while(true){

		for(int i = 0; i < NEW.size(); i++){
			for(int k = 0; k < vec.size(); k++){
				int tmp = (NEW[i]*vec[k])%M;

				if(NEW[i] != tmp && !used[NEW[i]][tmp]){
					used[NEW[i]][tmp] = true;
					G[NEW[i]].push_back(tmp);
					reverse_G[tmp].push_back(NEW[i]);
				}
				if(work[tmp])continue;
				work[tmp] = true;
				ADD.push_back(tmp);
			}
		}

		if(ADD.size() == 0)break;
		NEW = ADD;
		ADD.clear();
	}

	for(int i = 0; i < M; i++){
		if(!work[i]){

			printf("No\n");
			return 0;
		}
	}

	for(int i = 0; i < M; i++)check[i] = false;

	for(int i = 0; i < M;i++){
		if(!check[i])dfs(i);
	}

	for(int i = 0; i < M;i++)check[i] = false;

	group_index = -1;

	while(!S.empty()){
		if(!check[S.top()]){
			group_index++;

			reverse_dfs(S.top());
		}
		S.pop();
	}

	for(int i = 0; i <= group_index; i++){
		for(int k = 0; k < group[i].nodes.size(); k++){
			for(int p = 0; p < G[group[i].nodes[k]].size(); p++){
				int next_group = table[G[group[i].nodes[k]][p]];
				if(next_group != i && !scc_used[i][next_group]){
					scc_G[i].push_back(next_group);
					scc_used[i][next_group] = true;
				}
			}
		}
	}

	for(int i = 0; i <= group_index; i++){

		max_dist[i] = 0;
	}

	while(true){

		bool FLG = false;
		for(int i = 0; i <= group_index; i++){
			for(int k = 0; k < scc_G[i].size(); k++){
				int next = scc_G[i][k];
				if(max_dist[next] < max_dist[i]+1){
					max_dist[next] = max_dist[i]+1;
					FLG = true;
				}
			}
		}
		if(!FLG)break;
	}

	int maximum = 0;
	for(int i = 0; i <= group_index; i++){

		maximum = max(maximum,max_dist[i]);
	}

	if(maximum == group_index){

		printf("Yes\n");
	}else{

		printf("No\n");
	}

	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 32068
final_rank: 3

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

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=Int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}


struct SCC{
  vector< vector<Int> > G,R,T,C;
  vector<Int> vs,used,blg;
  SCC(){}
  SCC(Int n):G(n),R(n),used(n),blg(n){}

  void add_edge(Int u,Int v){
    G[u].emplace_back(v);
    R[v].emplace_back(u);
  }

  void dfs(Int v){
    used[v]=1;
    for(Int u:G[v])
      if(!used[u]) dfs(u);
    vs.emplace_back(v);
  }

  void rdfs(Int v,Int k){
    used[v]=1;
    blg[v]=k;
    C[k].emplace_back(v);
    for(Int u:R[v])
      if(!used[u]) rdfs(u,k);
  }

  Int build(){
    Int n=G.size();
    for(Int v=0;v<n;v++)
      if(!used[v]) dfs(v);

    fill(used.begin(),used.end(),0);
    Int k=0;
    for(Int i=n-1;i>=0;i--){
      if(!used[vs[i]]){
        T.emplace_back();
        C.emplace_back();
        rdfs(vs[i],k++);
      }
    }

    for(Int v=0;v<n;v++)
      for(Int u:G[v])
        if(blg[v]!=blg[u])
          T[blg[v]].push_back(blg[u]);

    for(Int i=0;i<k;i++){
      sort(T[i].begin(),T[i].end());
      T[i].erase(unique(T[i].begin(),T[i].end()),T[i].end());
    }
    return k;
  }

  Int operator[](Int k) const{return blg[k];}
};

//INSERT ABOVE HERE

const Int MAX = 2020;
Int G[MAX][MAX]={};

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int n,m;
  cin>>n>>m;
  auto as=read(n);

  for(Int i=0;i<m;i++)
    for(Int a:as)
      G[i][i*a%m]=1;

  SCC scc(m);
  for(Int i=0;i<m;i++)
    for(Int j=0;j<m;j++)
      if(i!=j and G[i][j]) scc.add_edge(i,j);

  Int k=scc.build();
  if(scc[1]!=0) drop("No");

  for(Int i=0;i+1<k;i++){
    Int flg=0;
    for(Int j:scc.T[i])
      flg|=(j==(i+1));
    if(!flg) drop("No");
  }
  drop("Yes");
  return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 83140
final_rank: 11

code_snippet: #include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)

using namespace std;
typedef long long ll;

const int INTINF = INT_MAX >> 1;

const ll MAX = 20100;
bool memo[MAX];
ll N, M;
vector<ll> v;

namespace internal {

template <class E> struct csr {
    std::vector<int> start;
    std::vector<E> elist;
    csr(int n, const std::vector<std::pair<int, E>>& edges)
        : start(n + 1), elist(edges.size()) {
        for (auto e : edges) {
            start[e.first + 1]++;
        }
        for (int i = 1; i <= n; i++) {
            start[i] += start[i - 1];
        }
        auto counter = start;
        for (auto e : edges) {
            elist[counter[e.first]++] = e.second;
        }
    }
};

// Reference:
// R. Tarjan,
// Depth-First Search and Linear Graph Algorithms
struct scc_graph {
  public:
    scc_graph(int n) : _n(n) {}

    int num_vertices() { return _n; }

    void add_edge(int from, int to) { edges.push_back({from, {to}}); }

    // @return pair of (# of scc, scc id)
    std::pair<int, std::vector<int>> scc_ids() {
        auto g = csr<edge>(_n, edges);
        int now_ord = 0, group_num = 0;
        std::vector<int> visited, low(_n), ord(_n, -1), ids(_n);
        visited.reserve(_n);
        auto dfs = [&](auto self, int v) -> void {
            low[v] = ord[v] = now_ord++;
            visited.push_back(v);
            for (int i = g.start[v]; i < g.start[v + 1]; i++) {
                auto to = g.elist[i].to;
                if (ord[to] == -1) {
                    self(self, to);
                    low[v] = std::min(low[v], low[to]);
                } else {
                    low[v] = std::min(low[v], ord[to]);
                }
            }
            if (low[v] == ord[v]) {
                while (true) {
                    int u = visited.back();
                    visited.pop_back();
                    ord[u] = _n;
                    ids[u] = group_num;
                    if (u == v) break;
                }
                group_num++;
            }
        };
        for (int i = 0; i < _n; i++) {
            if (ord[i] == -1) dfs(dfs, i);
        }
        for (auto& x : ids) {
            x = group_num - 1 - x;
        }
        return {group_num, ids};
    }

    std::vector<std::vector<int>> scc() {
        auto ids = scc_ids();
        int group_num = ids.first;
        std::vector<int> counts(group_num);
        for (auto x : ids.second) counts[x]++;
        std::vector<std::vector<int>> groups(ids.first);
        for (int i = 0; i < group_num; i++) {
            groups[i].reserve(counts[i]);
        }
        for (int i = 0; i < _n; i++) {
            groups[ids.second[i]].push_back(i);
        }
        return groups;
    }

  private:
    int _n;
    struct edge {
        int to;
    };
    std::vector<std::pair<int, edge>> edges;
};

}  // namespace internal

struct scc_graph {
  public:
    scc_graph() : internal(0) {}
    scc_graph(int n) : internal(n) {}

    void add_edge(int from, int to) {
        int n = internal.num_vertices();
        assert(0 <= from && from < n);
        assert(0 <= to && to < n);
        internal.add_edge(from, to);
    }

    std::vector<std::vector<int>> scc() { return internal.scc(); }

  private:
    internal::scc_graph internal;
};

int main(){


	cin >> N >> M;
	v.resize(N);
	rep(i, N){
		cin >> v[i];
	}

	scc_graph scc(M);
	rep(i, M){
		rep(j, N){
			scc.add_edge(i, i * v[j] % M);
		}
	}
	// rep(i, scc.scc().size()){
	// 	rep(j, scc.scc()[i].size()){
	// 		if(j) cout << " ";
	// 		cout << scc.scc()[i][j];
	// 	}
	// 	cout << endl;
	// }
	// cout << endl;

	bool ans = true;
	vector<vector<int> >  sccs = scc.scc();
	rep(i, sccs.size()){
		if(i == sccs.size()-1) break;
		bool id[2010];
		rep(j, 2010) id[j] = false;
		rep(j, sccs[i].size()){
			rep(k, N)
				id[sccs[i][j] * v[k] % M] =  true;
		}
		bool ok = false;
		rep(j, sccs[i+1].size()){
			if(id[sccs[i+1][j]]) ok = true;
		}
		if(!ok){
			ans = false;
			break;
		}
	}

	if(ans){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}


	// if(ok){
	// 	cout << "Yes" << endl;
	// }
	// else{
	// 	cout << "No" << endl;
	// }


    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 50272
final_rank: 6

code_snippet: #include "bits/stdc++.h"
using namespace std;
//#include "atcoder/all"
//using namespace atcoder;
#define int long long
#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 FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
	to = x;
	return *this;
  }

  operator int() const { return to; }
};
template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename G >
struct StronglyConnectedComponents {
  const G &g;
  UnWeightedGraph gg, rg;
  vector< int > comp, order, used;

  StronglyConnectedComponents(G &g) : g(g), gg(g.size()), rg(g.size()), comp(g.size(), -1), used(g.size()) {
	for(int i = 0; i < g.size(); i++) {
	  for(auto e : g[i]) {
		gg[i].emplace_back((int) e);
		rg[(int) e].emplace_back(i);
	  }
	}
  }

  int operator[](int k) {
	return comp[k];
  }

  void dfs(int idx) {
	if(used[idx]) return;
	used[idx] = true;
	for(int to : gg[idx]) dfs(to);
	order.push_back(idx);
  }

  void rdfs(int idx, int cnt) {
	if(comp[idx] != -1) return;
	comp[idx] = cnt;
	for(int to : rg[idx]) rdfs(to, cnt);
  }

  void build(UnWeightedGraph &t) {
	for(int i = 0; i < gg.size(); i++) dfs(i);
	reverse(begin(order), end(order));
	int ptr = 0;
	for(int i : order) if(comp[i] == -1) rdfs(i, ptr), ptr++;

	t.resize(ptr);
	for(int i = 0; i < g.size(); i++) {
	  for(auto &to : g[i]) {
		int x = comp[i], y = comp[to];
		if(x == y) continue;
		t[x].push_back(y);
	  }
	}
  }
};

signed main(){
	int N, M;
	cin >> N >> M;
	vector<int>a(N);
	cin >> a;
	vector<vector<int>>g(M);
	vector<vector<int>>d(M, vector<int>(M));
	REP(i, M) {
		REP(j, N) {
			d[i][i * a[j] % M] = 1;
		}
	}
	REP(i, M) {
		REP(j, M) {
			if(i != j && d[i][j]) g[i].emplace_back(j);
		}
	}
	StronglyConnectedComponents<vector<vector<int>>>scc(g);
	vector<vector<int>>buff;
	scc.build(buff);
	int s = scc[1];
	map<int, int>mp;
	REP(i, M) {
		mp[scc[i]]++;
	}
	vector<int>dp(buff.size());
	dp[s] = 1;
	REP(i, buff.size()) {
		for(auto to: buff[i]) {
			CHMAX(dp[to], dp[i] + 1);
		}
	}
	if(mp.size() == *max_element(ALL(dp))) out("Yes");
	else out("No");
}
accuracy: 1
time_ms: 90
memory_kb: 99096
final_rank: 14

code_snippet: //#include <tourist>
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//g++ yarudake.cpp -std=c++17 -I .
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

struct StronglyConnectedComponents
{
    vector<vector<int>> g;
    vector<vector<int>> to, from;
    vector<int> comp, order, used;
    StronglyConnectedComponents(vector<vector<int>> &g) : g(g), to(g.size()), from(g.size()), comp(g.size(), -1), used(g.size())
    {
        for (int i = 0; i < g.size(); i++)
        {
            for (auto x : g[i])
            {
                to[i].push_back(x);
                from[x].push_back(i);
            }
        }
    }
    int operator[](int k)
    {
        return comp[k];
    }
    void dfs(int now)
    {
        if (used[now])
            return;
        used[now] = true;
        for (int x : to[now])
            dfs(x);
        order.push_back(now);
    }
    void rdfs(int now, int cnt)
    {
        if (comp[now] != -1)
            return;
        comp[now] = cnt;
        for (int x : from[now])
            rdfs(x, cnt);
    }
    vector<vector<int>> build()
    {
        vector<vector<int>> t;
        for (int i = 0; i < to.size(); i++)
            dfs(i);
        reverse(order.begin(), order.end());
        int ptr = 0;
        for (int i : order)
            if (comp[i] == -1)
                rdfs(i, ptr), ptr++;

        t.resize(ptr);
        for (int i = 0; i < g.size(); i++)
        {
            for (auto v : to[i])
            {
                int x = comp[i], y = comp[v];
                if (x == y)
                    continue;
                t[x].push_back(y);
            }
        }
        return t;
    }
};
bool dfs(int k, vector<bool> check, vector<vector<int>> &t, int count)
{
    check[k] = true;
    count++;
    bool c = false;
    if (t.size() == count)
        return true;
    rep(i, t[k].size())
    {
        if (!check[t[k][i]])
        {
            c |= dfs(t[k][i], check, t, count);
        }
    }
    return c;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    rep(i, n) a[i] %= m;
    vector<vector<int>> g(m); //m点のグラフとして表現
    rep(i, n)
    {
        rep(j, m)
        {
            g[j].push_back((j * a[i] % m));
        }
    }
    StronglyConnectedComponents scc(g);
    vector<vector<int>> t = scc.build();
    /*
    vector<bool> check(t.size(),false);
    if(dfs(scc[1], check,t,0))yes;
    else no;
    */
    if (scc[1] != 0)
    {
        return no, 0;
    }
    rep(i, t.size()-1)
    {
        bool f = false;
        rep(j, t[i].size())
        {
            if (t[i][j] == i + 1)
                f = true;
        }
        if (!f)
            return no, 0;
    }
    yes;
}
accuracy: 1
time_ms: 80
memory_kb: 83572
final_rank: 13

code_snippet: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

void dfs1(vector<vector<pair<int,int>>> &graph, vector<int> &num, vector<int> &used, int node, int &con){

        if(used[node]) return ;

        used[node] = true;

        for(pair<int,int> next : graph[node]){
                dfs1(graph, num, used, next.first, con);
        }

        num[con++] = node;
}

void dfs2(vector<vector<pair<int,int>>> &graph, vector<int> &scc, vector<int> &used, int node, int same){

        if(used[node]) return ;

        used[node] = true;

        for(pair<int,int> next : graph[node]){
                dfs2(graph, scc, used, next.first, same);
        }

        scc[node] = same;
}

void Strongly_Connected_Components(vector<vector<pair<int,int>>> &graph, vector<int> &scc){
        vector<int>  used(graph.size()), num(graph.size());
        vector<vector<pair<int,int>>> graph2(graph.size());
        int con = 0;

        scc.resize(graph.size());

        // cout<<"A"<<endl;
        for(int i = 0; i < graph.size(); i++){
                dfs1(graph, num, used, i, con);
        }

        for(int i = 0; i < graph.size(); i++){
                for(int j = 0; j < graph[i].size(); j++){
                        graph2[graph[i][j].first].push_back(make_pair(i, graph[i][j].second));
                }
        }
        //cout<<"B"<<endl;

        used.clear();
        used.resize(graph.size());

        for(int i = (int)graph.size()-1, same = 0; i >= 0; i--){
                if(!used[num[i]]){
                        dfs2(graph2, scc, used, num[i], same);
                        same++;
                }
        }

}

signed main(){
  //ios::sync_with_stdio(false);
  // cin.tie(nullptr);

  vector<vector<pair<int,int>>> G;
  vector<vector<int>> g;
  vector<vector<int>> used;
  vector<int> a, b;
  vector<int> scc;
  int N, M;

  cin>>N>>M;

  G.resize(M);
  g.resize(M);

  a.resize(N);
  b.resize(M);

  used.resize(M, vector<int>(M,0));

  for(int i = 0; i < N; i++){

    cin>>a[i];

  }

  for(int i = 0; i < M; i++){
    for(int j = 0; j < N; j++){
      if(a[j]*i%M != i)G[i].push_back({(a[j]*i)%M, 1});
    }
  }
  //cout<<"<>"<<endl;
  Strongly_Connected_Components(G, scc);
  // cout<<"<>"<<endl;

  int con = 0;
  int one = scc[1];
  int zero = scc[0];
  // cout<<"[][]"<<endl;

  for(int i = 0; i < M; i++){ //cout<<"i = "<<i<<endl;
    if(b[scc[i]] == false)con++;
    b[scc[i]] = true;


    for(int j = 0; j < G[i].size(); j++){
      if(scc[i] == scc[G[i][j].first]) continue;

      if(used[scc[i]][scc[G[i][j].first]] == false) {
        g[scc[i]].push_back(scc[G[i][j].first]);
      }
      used[scc[i]][scc[G[i][j].first]] = false;
      //used[i][G[i][j].first] = true;
    }
  }

  // for(int i =0; i < M; i++){
  //   cout<<"i = "<<i<<" scc "<<scc[i]<<" "<<g[scc[i]].size()<<endl;
  // }

  int now = one;
  int con2 = 1;
  for(;;){
    //cout<<"fj;la"<<endl;
    if(g[now].size()) {
      now = g[now].front();
      //cout<<"now = "<<now<<endl;
      con2++;
    } else {
      break;
    }
  }

  if(con2 == con && now == zero) {
    cout<<"Yes"<<endl;
  } else {
    cout<<"No"<<endl;
  }


  return 0;
}
accuracy: 1
time_ms: 170
memory_kb: 183712
final_rank: 18

code_snippet: #pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <numeric>
#define IINF 1000000000
#define INF 3223372036854775807
#define MOD 1000000007
#define mod 1000000007
#define INT_MAX_ 2147483647
#define EPS (1e-10)
#define REP(i, a, n) fo-r (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
//#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
#define bit(n,k) ((n>>k)&1)
#define lg length()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define invp(a,p)pom(a,p-2,p)
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<Pll,ll> a,pair<Pll,ll> b){
        return a.fi.se>b.fi.se;
}
ll cmp2(pair<ll,ll> a,pair<ll,ll> b){
    if(a.fi!=b.fi)
        return  a.se<b.se;
    else
        return a.se>b.se;
}
//----------------------------------------------------------------------
struct unionfind{
    vector<int> rank,parent,size;
    unionfind() = default;
    unionfind(int n){
        for(int i=0;i<n;i++){
            rank.push_back(1);//树的高度
            parent.push_back(i);//根
            size.push_back(1);//树大小
        }
    }
    void setsize(int n) {
        for(int i=0;i<n;i++){
            rank.push_back(1);//树的高度
            parent.push_back(i);//根
            size.push_back(1);//树大小
        }
    }
    int getroot(int x){
        if(parent[x]==x)
            return x;
        return parent[x]=getroot(parent[x]);//押平路径加速以后的查找
    }
    bool issame(int a,int b){
        return getroot(a)==getroot(b);
    }
    void unite(int a,int b){
        a=getroot(a);
        b=getroot(b);
        if(a==b)
            return;
        else if(rank[a]>rank[b]){ //合并到高的树下
            parent[b]=a;
            size[a]+=size[b];
        }
        else if(rank[a]==rank[b]){
            parent[b]=a;
            rank[a]++;
            size[a]+=size[b];
        }
        else{
            parent[a]=b;
            size[b]+=size[a];
        }
    }
};

//強連結成分分解 O(V+E)　Union Findを使って一部の機能を実装してる
struct StronglyConnectedComponents {
    vector<vector<int>> E, rE;
    vector<int> belong;//belong[i] := i番目の頂点が属してる強連結成分の集合番号
    vector<int> order, used;
    int N;
    int anscnt = 1;//集合番号は1-idxで実装した
    unionfind uf;

    StronglyConnectedComponents(vector<vector<int>> e) {
        E = e;
        N = E.size();
        rE.resize(N);
        used.resize(N);
        belong.resize(N);
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < E[i].size(); j++) {
                rE[E[i][j]].push_back(i);
            }
        }
        uf.setsize(N);
    }

    void dfs(int pos, int bef) {
        used[pos] = 1;
        for (int i = 0; i < E[pos].size(); i++) {
            int nxt = E[pos][i];
            if (nxt == bef)continue;
            if (!used[nxt])dfs(nxt, pos);
        }
        order.push_back(pos);
    }

    void rdfs(int pos, int bef) {
        belong[pos] = anscnt;
        if (bef != -1)uf.unite(pos, bef);
        for (int i = 0; i < rE[pos].size(); i++) {
            int nxt = rE[pos][i];
            if (nxt == bef || belong[nxt] != 0) {
                continue;
            }
            rdfs(nxt, pos);
        }
    }

    void conduct() {
        for (int i = 0; i < N; i++)
            if (used[i] == 0)dfs(i, -1);
        reverse(order.begin(), order.end());
        for (int i = 0; i < N; i++) {
            if (belong[order[i]] == 0)rdfs(order[i], -1), anscnt++;
        }
    }

    int operator[](int k) {
        return belong[k];
    }

    vector<vector<int>> trans_adjacency_list() {
        //i番目の今日連結グループの中身を返す。 例によって1-idxで
        vector<vector<int>> ret(anscnt);
        for (int i = 0; i < N; i++) {
            ret[belong[i]].push_back(i);
        }
        return ret;
    }

    vector<vector<int>> get_SCC_DAG() {
        //強連結成分を頂点としたグラフを作る。
        //強連結成分の番号はbelong[i]にある通りで1-idxで実装されてる
        //UFを使うことでO(N)でできた
        vector<vector<int>> ret;
        ret.resize(anscnt);
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < E[i].size(); j++) {
                int nxt = E[i][j];
                if (!uf.issame(i, nxt)) {
                    ret[belong[i]].push_back(belong[nxt]);
                }
            }
        }
        return ret;
    }
};

ll maxdd = 0;
void dfs(ll now, ll pre, V<V<int>>& ed, V<bool>&color, ll d){
    chmax(maxdd,d);
    for(ll i=0;i<ed[now].size();i++){
        ll nxt = ed[now][i];
        if(pre==nxt)continue;
        if(color[nxt])continue;
        color[nxt]=1;
        dfs(nxt,now,ed,color,d+1);
    }
}
//----------------------------------------------------------------------
int main(int argc, char * argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_t=clock();
    //freopen("big.txt", "r", stdin);
    //freopen("out3.txt", "w", stdout);
    //------------------------------
    ll n,m;cin>>n>>m;
    V<ll>a(n);
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    V<V<int>>G;
    G.resize(m);
    for(ll i=0;i<m;i++){
        for(ll j=0;j<n;j++){
            G[i].pb(i*a[j]%m);
        }
    }
    StronglyConnectedComponents scc(G);
    scc.conduct();
    auto scc_e = scc.get_SCC_DAG();
    auto scc_belong = scc.belong[1];
    V<bool>color(scc_e.size(),0);
    color[scc_belong]=1;
    dfs(scc_belong, -1, scc_e, color,1);

    if(maxdd!=scc_e.size()-1)cout<<"No"<<endl;
    else cout<<"Yes"<<Endl;
    //------------------------------
    //fclose(stdin);
    //fclose(stdout);
    //ll end_t=clock();cout<<"time="<<end_t-begin_t<<"ms"<<endl;
    //------------------------------- 
    return 0;
}
//----------------------------------------------------------------------
accuracy: 1
time_ms: 110
memory_kb: 73664
final_rank: 12

code_snippet: #pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <numeric>
#define IINF 1000000000
#define INF 3223372036854775807
#define MOD 1000000007
#define mod 1000000007
#define INT_MAX_ 2147483647
#define EPS (1e-10)
#define REP(i, a, n) fo-r (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
//#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
#define bit(n,k) ((n>>k)&1)
#define lg length()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define invp(a,p)pom(a,p-2,p)
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<Pll,ll> a,pair<Pll,ll> b){
        return a.fi.se>b.fi.se;
}
ll cmp2(pair<ll,ll> a,pair<ll,ll> b){
    if(a.fi!=b.fi)
        return  a.se<b.se;
    else
        return a.se>b.se;
}
//----------------------------------------------------------------------
struct unionfind{
    vector<int> rank,parent,size;
    unionfind() = default;
    unionfind(int n){
        for(int i=0;i<n;i++){
            rank.push_back(1);//树的高度
            parent.push_back(i);//根
            size.push_back(1);//树大小
        }
    }
    void setsize(int n) {
        for(int i=0;i<n;i++){
            rank.push_back(1);//树的高度
            parent.push_back(i);//根
            size.push_back(1);//树大小
        }
    }
    int getroot(int x){
        if(parent[x]==x)
            return x;
        return parent[x]=getroot(parent[x]);//押平路径加速以后的查找
    }
    bool issame(int a,int b){
        return getroot(a)==getroot(b);
    }
    void unite(int a,int b){
        a=getroot(a);
        b=getroot(b);
        if(a==b)
            return;
        else if(rank[a]>rank[b]){ //合并到高的树下
            parent[b]=a;
            size[a]+=size[b];
        }
        else if(rank[a]==rank[b]){
            parent[b]=a;
            rank[a]++;
            size[a]+=size[b];
        }
        else{
            parent[a]=b;
            size[b]+=size[a];
        }
    }
};

//強連結成分分解 O(V+E)　Union Findを使って一部の機能を実装してる
struct StronglyConnectedComponents {
    vector<vector<ll>> E, rE;
    vector<int> belong;//belong[i] := i番目の頂点が属してる強連結成分の集合番号
    vector<int> order, used;
    int N;
    int anscnt = 1;//集合番号は1-idxで実装した
    unionfind uf;

    StronglyConnectedComponents(vector<vector<ll>> e) {
        E = e;
        N = E.size();
        rE.resize(N);
        used.resize(N);
        belong.resize(N);
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < E[i].size(); j++) {
                rE[E[i][j]].push_back(i);
            }
        }
        uf.setsize(N);
    }

    void dfs(int pos, int bef) {
        used[pos] = 1;
        for (int i = 0; i < E[pos].size(); i++) {
            int nxt = E[pos][i];
            if (nxt == bef)continue;
            if (!used[nxt])dfs(nxt, pos);
        }
        order.push_back(pos);
    }

    void rdfs(int pos, int bef) {
        belong[pos] = anscnt;
        if (bef != -1)uf.unite(pos, bef);
        for (int i = 0; i < rE[pos].size(); i++) {
            int nxt = rE[pos][i];
            if (nxt == bef || belong[nxt] != 0) {
                continue;
            }
            rdfs(nxt, pos);
        }
    }

    void conduct() {
        for (int i = 0; i < N; i++)
            if (used[i] == 0)dfs(i, -1);
        reverse(order.begin(), order.end());
        for (int i = 0; i < N; i++) {
            if (belong[order[i]] == 0)rdfs(order[i], -1), anscnt++;
        }
    }

    int operator[](int k) {
        return belong[k];
    }

    vector<vector<ll>> trans_adjacency_list() {
        //i番目の今日連結グループの中身を返す。 例によって1-idxで
        vector<vector<ll>> ret(anscnt);
        for (int i = 0; i < N; i++) {
            ret[belong[i]].push_back(i);
        }
        return ret;
    }

    vector<vector<ll>> get_SCC_DAG() {
        //強連結成分を頂点としたグラフを作る。
        //強連結成分の番号はbelong[i]にある通りで1-idxで実装されてる
        //UFを使うことでO(N)でできた
        vector<vector<ll>> ret;
        ret.resize(anscnt);
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < E[i].size(); j++) {
                int nxt = E[i][j];
                if (!uf.issame(i, nxt)) {
                    ret[belong[i]].push_back(belong[nxt]);
                }
            }
        }
        return ret;
    }
};

ll maxdd = 0;
void dfs(ll now, ll pre, V<V<ll>>& ed, V<bool>&color, ll d){
    chmax(maxdd,d);
    for(ll i=0;i<ed[now].size();i++){
        ll nxt = ed[now][i];
        if(pre==nxt)continue;
        if(color[nxt])continue;
        color[nxt]=1;
        dfs(nxt,now,ed,color,d+1);
    }
}
//----------------------------------------------------------------------
int main(int argc, char * argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_t=clock();
    //freopen("big.txt", "r", stdin);
    //freopen("out3.txt", "w", stdout);
    //------------------------------
    ll n,m;cin>>n>>m;
    V<ll>a(n);
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    V<V<ll>>G;
    G.resize(m);
    for(ll i=0;i<m;i++){
        for(ll j=0;j<n;j++){
            G[i].pb(i*a[j]%m);
        }
    }
    StronglyConnectedComponents scc(G);
    scc.conduct();
    auto scc_e = scc.get_SCC_DAG();
    auto scc_belong = scc.belong[1];
    V<bool>color(scc_e.size(),0);
    color[scc_belong]=1;
    dfs(scc_belong, -1, scc_e, color,1);

    if(maxdd!=scc_e.size()-1)cout<<"No"<<endl;
    else cout<<"Yes"<<Endl;
    //------------------------------
    //fclose(stdin);
    //fclose(stdout);
    //ll end_t=clock();cout<<"time="<<end_t-begin_t<<"ms"<<endl;
    //------------------------------- 
    return 0;
}
//----------------------------------------------------------------------
accuracy: 1
time_ms: 140
memory_kb: 142508
final_rank: 16

code_snippet: #include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 2020000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    for(auto itr = a.begin(); itr != a.end(); itr++){
		cout << *itr << " ";
	}
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
	cout << "debug: " << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << "debug: " << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
//const int mod = 1e9 + 7;
const int mod = 998244353;

template< typename G >
struct StronglyConnectedComponents {
  const G &g;
  vvl gg, rg;
  vector< int > comp, order, used;

  StronglyConnectedComponents(G &g) : g(g), gg(g.size()), rg(g.size()), comp(g.size(), -1), used(g.size()) {
    for(int i = 0; i < g.size(); i++) {
      for(auto e : g[i]) {
        gg[i].emplace_back((int) e);
        rg[(int) e].emplace_back(i);
      }
    }
  }

  int operator[](int k) {
    return comp[k];
  }

  void dfs(int idx) {
    if(used[idx]) return;
    used[idx] = true;
    for(int to : gg[idx]) dfs(to);
    order.push_back(idx);
  }

  void rdfs(int idx, int cnt) {
    if(comp[idx] != -1) return;
    comp[idx] = cnt;
    for(int to : rg[idx]) rdfs(to, cnt);
  }

  int build(vvl &t) {
    for(int i = 0; i < gg.size(); i++) dfs(i);
    reverse(begin(order), end(order));
    int ptr = 0;
    for(int i : order) if(comp[i] == -1) rdfs(i, ptr), ptr++;

    t.resize(ptr);
    for(int i = 0; i < g.size(); i++) {
      for(auto &to : g[i]) {
        int x = comp[i], y = comp[to];
        if(x == y) continue;
        t[x].push_back(y);
      }
    }
	return ptr;
  }
};


int main(){
	int n,m; cin >> n >> m;
	vl a(n); rep(i,n) cin >> a[i], a[i] %= m;
	vvl G(m);
	for(int i=1; i<m; i++){
		rep(j,n){
			G[i].push_back(i*a[j]%m);
		}
	}
	StronglyConnectedComponents<vvl> scc(G);
	vvl g;
	scc.build(g);
	int t = scc[1];
	if(t != 0){
		puts("No");
		return 0;
	}
	queue<int> q;
	q.push(1);
	int now = 0;
	while(1){
		int nxt = -1;
		for(auto v : g[now]){
			if(v == now + 1){
				nxt = now + 1;
				break;
			}
		}
		if(nxt != now + 1) break;
		now = nxt;
	}
	if(now == scc[0]) puts("Yes");
	else puts("No");
}
accuracy: 1
time_ms: 130
memory_kb: 129756
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;  
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define Rep(i, a, b) for(ll i = a; i <= b; i++)
#define repr(i, a, b) for(ll i = b-1; i >= a; i--)
// #define _GLIBCXX_DEBUG
template <class T> using V = vector<T>;
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
const double pi = acos(-1.0);
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
// #define fi first
// #define se second
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};

/*--------------------------------------------------------------------------------
--------------------------------------------------------------------------------*/

using UnWeightedGraph = vector<vector<int>>;

template< typename G >
struct StronglyConnectedComponents {
  const G &g;
  UnWeightedGraph gg, rg;
  vector< int > comp, order, used;

  StronglyConnectedComponents(G &g) : g(g), gg(g.size()), rg(g.size()), comp(g.size(), -1), used(g.size()) {
    for(int i = 0; i < g.size(); i++) {
      for(auto e : g[i]) {
        gg[i].emplace_back((int) e);
        rg[(int) e].emplace_back(i);
      }
    }
  }

  int operator[](int k) {
    return comp[k];
  }

  void dfs(int idx) {
    if(used[idx]) return;
    used[idx] = true;
    for(int to : gg[idx]) dfs(to);
    order.push_back(idx);
  }

  void rdfs(int idx, int cnt) {
    if(comp[idx] != -1) return;
    comp[idx] = cnt;
    for(int to : rg[idx]) rdfs(to, cnt);
  }

  void build(UnWeightedGraph &t) {
    for(int i = 0; i < gg.size(); i++) dfs(i);
    reverse(begin(order), end(order));
    int ptr = 0;
    for(int i : order) if(comp[i] == -1) rdfs(i, ptr), ptr++;

    t.resize(ptr);
    for(int i = 0; i < g.size(); i++) {
      for(auto &to : g[i]) {
        int x = comp[i], y = comp[to];
        if(x == y) continue;
        t[x].push_back(y);
      }
    }
  }
};

void solve(){
    ll N, M;
    cin >> N >> M;
    V<ll> a(N);
    rep(i, 0, N) cin >> a[i];
    UnWeightedGraph G(M), buff;
    rep(from, 0, M){
        rep(i, 0, N){
            ll to = from*a[i]%M;
            G[from].emplace_back(to);
        }
    }
    StronglyConnectedComponents<UnWeightedGraph> scc(G);
    scc.build(buff);
    V<set<ll>> buf(sz(buff));
    //debug
    // cout << scc[1] << " " << scc[0] << endl;
    rep(i, 0, sz(buff)){
        // cout << i << " : ";
        // rep(j, 0, sz(buff[i])) cout << buff[i][j] << " ";
        // cout << endl;
        rep(j, 0, sz(buff[i])) buf[i].insert(buff[i][j]);
    }
    //
    // scc[1] -> scc[0] の最長経路を求める
    V<ll> d(sz(buff), -INF);
    d[scc[1]] = 0;
    rep(i, 0, sz(buff)){
        rep(from, 0, sz(buff)){
            for(auto to : buf[from]) chmax(d[to], d[from]+1);
        }
    }
    if(d[scc[0]] == sz(buff)-1) puts("Yes");
    else puts("No");

    return;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();

    return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 68012
final_rank: 9

code_snippet: #pragma GCC optimize("Ofast")
#include<bits/stdc++.h>

#ifndef ATCODER_INTERNAL_SCC_HPP
#define ATCODER_INTERNAL_SCC_HPP 1

namespace atcoder {
namespace internal {

template <class E> struct csr {
    std::vector<int> start;
    std::vector<E> elist;
    csr(int n, const std::vector<std::pair<int, E>>& edges)
        : start(n + 1), elist(edges.size()) {
        for (auto e : edges) {
            start[e.first + 1]++;
        }
        for (int i = 1; i <= n; i++) {
            start[i] += start[i - 1];
        }
        auto counter = start;
        for (auto e : edges) {
            elist[counter[e.first]++] = e.second;
        }
    }
};

// Reference:
// R. Tarjan,
// Depth-First Search and Linear Graph Algorithms
struct scc_graph {
  public:
    scc_graph(int n) : _n(n) {}

    int num_vertices() { return _n; }

    void add_edge(int from, int to) { edges.push_back({from, {to}}); }

    // @return pair of (# of scc, scc id)
    std::pair<int, std::vector<int>> scc_ids() {
        auto g = csr<edge>(_n, edges);
        int now_ord = 0, group_num = 0;
        std::vector<int> visited, low(_n), ord(_n, -1), ids(_n);
        visited.reserve(_n);
        auto dfs = [&](auto self, int v) -> void {
            low[v] = ord[v] = now_ord++;
            visited.push_back(v);
            for (int i = g.start[v]; i < g.start[v + 1]; i++) {
                auto to = g.elist[i].to;
                if (ord[to] == -1) {
                    self(self, to);
                    low[v] = std::min(low[v], low[to]);
                } else {
                    low[v] = std::min(low[v], ord[to]);
                }
            }
            if (low[v] == ord[v]) {
                while (true) {
                    int u = visited.back();
                    visited.pop_back();
                    ord[u] = _n;
                    ids[u] = group_num;
                    if (u == v) break;
                }
                group_num++;
            }
        };
        for (int i = 0; i < _n; i++) {
            if (ord[i] == -1) dfs(dfs, i);
        }
        for (auto& x : ids) {
            x = group_num - 1 - x;
        }
        return {group_num, ids};
    }

    std::vector<std::vector<int>> scc() {
        auto ids = scc_ids();
        int group_num = ids.first;
        std::vector<int> counts(group_num);
        for (auto x : ids.second) counts[x]++;
        std::vector<std::vector<int>> groups(ids.first);
        for (int i = 0; i < group_num; i++) {
            groups[i].reserve(counts[i]);
        }
        for (int i = 0; i < _n; i++) {
            groups[ids.second[i]].push_back(i);
        }
        return groups;
    }

  private:
    int _n;
    struct edge {
        int to;
    };
    std::vector<std::pair<int, edge>> edges;
};

}  // namespace internal

}  // namespace atcoder

#endif  // ATCODER_INTERNAL_SCC_HPP

#ifndef ATCODER_SCC_HPP
#define ATCODER_SCC_HPP 1
namespace atcoder {
struct scc_graph {
  public:
    scc_graph() : internal(0) {}
    scc_graph(int n) : internal(n) {}
    void add_edge(int from, int to) {
        int n = internal.num_vertices();
        assert(0 <= from && from < n);
        assert(0 <= to && to < n);
        internal.add_edge(from, to);
    }
    std::vector<std::vector<int>> scc() { return internal.scc(); }
  private:
    internal::scc_graph internal;
};
}  // namespace atcoder
#endif  // ATCODER_SCC_HPP

//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
using namespace atcoder;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};
//vector<int> bucket[MAX_N/1000];

vector<int> edge[2000];

int main(void){
    int N,M;
    cin >> N >> M;
    scc_graph g(M);
    lint A[N];
    rep(i,N) cin >> A[i];
    rep(i,N) A[i]%=M;
    rep(i,M) rep(j,N){
        lint from=i,to=(i*A[j])%M;
        if(from!=to){
            g.add_edge(from,to);
            edge[from].push_back(to);
        }
    }
    vector<vector<int>> res=g.scc();
    int belong[M];
    rep(i,res.size()) rep(j,res[i].size()) belong[res[i][j]]=i;
    bool ans=true;
    if(find(res[0].begin(),res[0].end(),1)==res[0].end()) ans=false;
    bool cn[res.size()-1]={};
    rep(i,M) rep(j,edge[i].size()){
        if(belong[edge[i][j]]-belong[i]==1) cn[belong[i]]=true;
    }
    bool chk=true;
    rep(i,res.size()-1) if(!cn[i]) chk=false;
    if(!chk) ans=false;
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}
accuracy: 1
time_ms: 90
memory_kb: 65692
final_rank: 7

code_snippet: #pragma GCC optimize("Ofast")
#include<bits/stdc++.h>

#ifndef ATCODER_INTERNAL_SCC_HPP
#define ATCODER_INTERNAL_SCC_HPP 1

namespace atcoder {
namespace internal {

template <class E> struct csr {
    std::vector<int> start;
    std::vector<E> elist;
    csr(int n, const std::vector<std::pair<int, E>>& edges)
        : start(n + 1), elist(edges.size()) {
        for (auto e : edges) {
            start[e.first + 1]++;
        }
        for (int i = 1; i <= n; i++) {
            start[i] += start[i - 1];
        }
        auto counter = start;
        for (auto e : edges) {
            elist[counter[e.first]++] = e.second;
        }
    }
};

// Reference:
// R. Tarjan,
// Depth-First Search and Linear Graph Algorithms
struct scc_graph {
  public:
    scc_graph(int n) : _n(n) {}

    int num_vertices() { return _n; }

    void add_edge(int from, int to) { edges.push_back({from, {to}}); }

    // @return pair of (# of scc, scc id)
    std::pair<int, std::vector<int>> scc_ids() {
        auto g = csr<edge>(_n, edges);
        int now_ord = 0, group_num = 0;
        std::vector<int> visited, low(_n), ord(_n, -1), ids(_n);
        visited.reserve(_n);
        auto dfs = [&](auto self, int v) -> void {
            low[v] = ord[v] = now_ord++;
            visited.push_back(v);
            for (int i = g.start[v]; i < g.start[v + 1]; i++) {
                auto to = g.elist[i].to;
                if (ord[to] == -1) {
                    self(self, to);
                    low[v] = std::min(low[v], low[to]);
                } else {
                    low[v] = std::min(low[v], ord[to]);
                }
            }
            if (low[v] == ord[v]) {
                while (true) {
                    int u = visited.back();
                    visited.pop_back();
                    ord[u] = _n;
                    ids[u] = group_num;
                    if (u == v) break;
                }
                group_num++;
            }
        };
        for (int i = 0; i < _n; i++) {
            if (ord[i] == -1) dfs(dfs, i);
        }
        for (auto& x : ids) {
            x = group_num - 1 - x;
        }
        return {group_num, ids};
    }

    std::vector<std::vector<int>> scc() {
        auto ids = scc_ids();
        int group_num = ids.first;
        std::vector<int> counts(group_num);
        for (auto x : ids.second) counts[x]++;
        std::vector<std::vector<int>> groups(ids.first);
        for (int i = 0; i < group_num; i++) {
            groups[i].reserve(counts[i]);
        }
        for (int i = 0; i < _n; i++) {
            groups[ids.second[i]].push_back(i);
        }
        return groups;
    }

  private:
    int _n;
    struct edge {
        int to;
    };
    std::vector<std::pair<int, edge>> edges;
};

}  // namespace internal

}  // namespace atcoder

#endif  // ATCODER_INTERNAL_SCC_HPP

#ifndef ATCODER_SCC_HPP
#define ATCODER_SCC_HPP 1
namespace atcoder {
struct scc_graph {
  public:
    scc_graph() : internal(0) {}
    scc_graph(int n) : internal(n) {}
    void add_edge(int from, int to) {
        int n = internal.num_vertices();
        assert(0 <= from && from < n);
        assert(0 <= to && to < n);
        internal.add_edge(from, to);
    }
    std::vector<std::vector<int>> scc() { return internal.scc(); }
  private:
    internal::scc_graph internal;
};
}  // namespace atcoder
#endif  // ATCODER_SCC_HPP

//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
using namespace atcoder;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};
//vector<int> bucket[MAX_N/1000];

vector<int> edge[2000];

int main(void){
    int N,M;
    cin >> N >> M;
    scc_graph g(M);
    lint A[N];
    rep(i,N) cin >> A[i];
    rep(i,N) A[i]%=M;
    rep(i,M) rep(j,N){
        lint from=i,to=(i*A[j])%M;
        if(from!=to){
            g.add_edge(from,to);
            edge[from].push_back(to);
        }
    }
    vector<vector<int>> res=g.scc();
    int belong[N];
    rep(i,res.size()) rep(j,res[i].size()) belong[res[i][j]]=i;
    bool ans=true;
    if(find(res[0].begin(),res[0].end(),1)==res[0].end()) ans=false;
    bool cn[res.size()-1]={};
    rep(i,M) rep(j,edge[i].size()){
        if(belong[edge[i][j]]-belong[i]==1) cn[belong[i]]=true;
    }
    bool chk=true;
    rep(i,res.size()-1) if(!cn[i]) chk=false;
    if(!chk) ans=false;
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}
accuracy: 0.30952380952380953
time_ms: 20
memory_kb: 24232
final_rank: 20