Problem:
Problem D:
Dial Key
You are a secret agent from the Intelligence Center of Peacemaking Committee. You've just sneaked into a secret laboratory of an evil company, Automated Crime Machines.
Your mission is to get a confidential document kept in the laboratory. To reach the document, you need to unlock the door to the safe where it is kept. You have to unlock the door in a correct way and with a great care; otherwise an alarm would ring and you would be caught by the secret police.
The lock has a circular dial with
N
lights around it and a hand pointing to one of them. The lock also has
M
buttons to control the hand. Each button has a number
L
i
printed on it.
Initially, all the lights around the dial are turned off. When the
i
-th button is pressed, the hand revolves clockwise by
L
i
lights, and the pointed light is turned on. You are allowed to press the buttons exactly
N
times. The lock opens only when you make all the lights turned on.
For example, in the case with
N
= 6,
M
= 2,
L
1
= 2 and
L
2
= 5, you can unlock the door by pressing buttons 2, 2, 2, 5, 2 and 2 in this order.
There are a number of doors in the laboratory, and some of them don’t seem to be unlockable. Figure out which lock can be opened, given the values
N
,
M
, and
L
i
's.
Input
The input starts with a line containing two integers, which represent
N
and
M
respectively.
M
lines follow, each of which contains an integer representing
L
i
.
It is guaranteed that 1 ≤
N
≤ 10
9
, 1 ≤
M
≤ 10
5
, and 1 ≤
L
i
≤
N
for each
i
= 1, 2, ...
N
.
Output
Output a line with "Yes" (without quotes) if the lock can be opened, and "No" otherwise.
Sample Input 1
6 2
2
5
Output for the Sample Input 1
Yes
Sample Input 2
3 1
1
Output for the Sample Input 2
Yes
Sample Input 3
4 2
2
4
Output for the Sample Input 3
No

Submitted solutions:

code_snippet: #include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <ctime>
typedef long long ll;
#define clr(x,a) memset(x,a,sizeof(x))
#define sz(x) (int)x.size()
#define see(x) cerr<<#x<<" "<<x<<endl
#define se(x) cerr<<" "<<x
#define pb push_back
#define mp make_pair
#define rep(i,l,r) for (int i=l;i<=r;i++)
using namespace std;
int x,n,m,a[100010];
int check(){
    int mi=1000000000,ma=-1;
    rep(i,1,m) {
        if (a[i]!=0) {
            mi=min(mi,a[i]);
            ma=max(ma,a[i]);
        }
    }
    if (mi==ma) return 0;
    x=mi;return 1;
}
int main()
{

	cin>>n>>m;
	rep(i,1,m) scanf("%d",&a[i]);
	rep(i,1,m) a[i]=__gcd(n,a[i]);
	while (check()){
        rep(i,1,m) {
            if (a[i]!=x) a[i]=a[i]%x;
            if (a[i]==1) {
            cout<<"Yes"<<endl;return 0;
            }
        }
	}
	rep(i,1,m) if (a[i]==1) {
            cout<<"Yes"<<endl;return 0;
    }
	cout<<"No"<<endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3868
final_rank: 12

code_snippet: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n,m;
  cin>>n>>m;

  Int g=n;
  for(Int i=0;i<m;i++){
    Int x;
    cin>>x;
    g=__gcd(g,x);
  }
  
  cout<<(g==1?"Yes":"No")<<endl;
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3240
final_rank: 11

code_snippet: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n,m;
  cin>>n>>m;
  auto check=[](Int n,Int x){
    if(__gcd(n,x)==1){
      cout<<"Yes"<<endl;
      exit(0);
    }
  };

  vector<Int> v,w;
  for(Int i=0;i<m;i++){
    Int x;
    cin>>x;
    check(n,x);
    v.emplace_back(__gcd(n,x));
    w.emplace_back(x);
  }

  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  
  for(Int i:v)
    for(Int j:w)
      check(i,j);
  
  cout<<"No"<<endl;
  return 0;
}
accuracy: 0.4852941176470588
time_ms: 10
memory_kb: 3328
final_rank: 16

code_snippet: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n,m;
  cin>>n>>m;
  auto check=[](Int n,Int x){
    if(__gcd(n,x)==1){
      cout<<"Yes"<<endl;
      exit(0);
    }
  };

  vector<int> v,w;
  for(Int i=0;i<m;i++){
    Int x;
    cin>>x;
    check(n,x);
    if(x<n&&n%x==0) v.emplace_back(x);
    w.emplace_back(x);
  }

  for(int i:v)
    for(int j:w)
      check(i,j);
  
  cout<<"No"<<endl;
  return 0;
}
accuracy: 0.4852941176470588
time_ms: 740
memory_kb: 3320
final_rank: 17

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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  for(int i = 0; i < M; i++) {
    int x;
    cin >> x;
    N = __gcd(N, x);
  }
  if(N == 1) cout << "Yes" << endl;
  else cout << "No" << endl;
}
accuracy: 1
time_ms: 30
memory_kb: 3136
final_rank: 9

code_snippet: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n,m;
  cin>>n>>m;
  auto check=[](Int n,Int x){
    if(__gcd(n,x)==1){
      cout<<"Yes"<<endl;
      exit(0);
    }
  };

  vector<int> v;
  for(Int i=0;i<m;i++){
    Int x;
    cin>>x;
    check(n,x);
    if(x<n) v.emplace_back(x);
  }

  sort(v.begin(),v.end());
  
  for(Int i:v){
    for(Int j:v){
      if(j>=i) break;
      check(i,j);
    }
  }
  cout<<"No"<<endl;
  return 0;
}
accuracy: 0.4852941176470588
time_ms: 7490
memory_kb: 3352
final_rank: 19

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

vector<int>primes;
void hurui(const int amax) {
	static bool flag = false;
	if (flag)return;
	vector<int>sos;
	sos = vector<int>(amax + 1, true);
	sos[0] = false; sos[1] = false;
	for (int i = 2; i <= amax; ++i) {
		if (sos[i]) {
			for (int j = 2 * i; j <= amax; j += i)sos[j] = false;
		}
	}
	for (int i = 0; i <= amax; ++i) {
		if (sos[i]) {
			primes.push_back(i);
		}
	}
	flag = true;
}
map<long long int, int>soinnsuu(long long int a) {
	hurui(1e6);
	map<long long int, int>ans;
	for (auto i : primes) {
		if (i> a)break;
		while (a%i == 0) {
			ans[i]++;
			a /= i;
		}
	}
	if (a != 1)ans[a]++;
	return ans;
}

int main() {
	int N,M;cin>>N>>M;
	auto n_mp(soinnsuu(N));
	map<int,bool>valid_mp;
	for (auto nm : n_mp) {
		valid_mp[nm.first]=false;
	}
	for (int i = 0; i < M; ++i) {
		int num;cin>>num;
		for (auto nm : n_mp) {
			if (num%nm.first) {
				valid_mp[nm.first]=true;
			}
		}
	}
	bool ok = all_of(valid_mp.begin(), valid_mp.end(), [](const pair<int, bool>&p) {
		return p.second;
	});
	if(ok)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 7420
final_rank: 13

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

vector<int>primes;
void hurui(const int amax) {
	static bool flag = false;
	if (flag)return;
	vector<int>sos;
	sos = vector<int>(amax + 1, true);
	sos[0] = false; sos[1] = false;
	for (int i = 2; i <= amax; ++i) {
		if (sos[i]) {
			for (int j = 2 * i; j <= amax; j += i)sos[j] = false;
		}
	}
	for (int i = 0; i <= amax; ++i) {
		if (sos[i]) {
			primes.push_back(i);
		}
	}
	flag = true;
}
map<long long int, int>soinnsuu(long long int a) {
	hurui(1e6);
	map<long long int, int>ans;
	for (auto i : primes) {
		if (i> a)break;
		while (a%i == 0) {
			ans[i]++;
			a /= i;
		}
	}
	if (a != 1)ans[a]++;
	return ans;
}

int main() {
	int N,M;cin>>N>>M;
	auto n_mp(soinnsuu(N));
	map<int,bool>valid_mp;
	for (auto nm : n_mp) {
		valid_mp[nm.first]=true;
	}
	for (int i = 0; i < M; ++i) {
		int num;cin>>num;
		for (auto nm : n_mp) {
			if (num%nm.first) {
				valid_mp[nm.first]=true;
			}
		}
	}
	bool ok = all_of(valid_mp.begin(), valid_mp.end(), [](const pair<int, bool>&p) {
		return p.second;
	});
	if(ok)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}
accuracy: 0.10294117647058823
time_ms: 10
memory_kb: 7436
final_rank: 20

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int calc(int x,int y){
	if(y == 0){
		return x;
	}else{
		return calc(y,x%y);
	}
}

int main(){

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

	int tmp,common;

	scanf("%d",&tmp);

	if(tmp >= N){
		common = calc(tmp,N);
	}else{
		common = calc(N,tmp);
	}

	for(int loop = 1; loop < M; loop++){
		scanf("%d",&tmp);
		if(tmp >= common){
			common = calc(tmp,common);
		}else{
			common = calc(common,tmp);
		}
	}

	if(common == 1){
		printf("Yes\n");
	}else{
		printf("No\n");
	}

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3172
final_rank: 10

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int calc(int x,int y){
	if(y == 0){
		return x;
	}else{
		return calc(y,x%y);
	}
}

int main(){

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

	int tmp,common;

	scanf("%d",&tmp);
	common = tmp;
	for(int loop = 1; loop < M; loop++){
		scanf("%d",&tmp);
		if(tmp >= common){
			common = calc(tmp,common);
		}else{
			common = calc(common,tmp);
		}
	}

	if(common == 1){
		printf("Yes\n");
	}else{
		printf("No\n");
	}

	return 0;
}
accuracy: 0.9852941176470589
time_ms: 10
memory_kb: 3172
final_rank: 14

code_snippet: #include<iostream>
using namespace std;
int gcd(int a, int b) { if (b == 0)return a; return gcd(b, a%b); }
int main() {
	int n, p, t, a; cin >> n >> p; t = n;
	for (int i = 0; i < p; i++) {
		cin >> a; t = gcd(t, a);
	}
	if (t >= 2)cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3100
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
void reader(int *x) {
	int k = getchar_unlocked(); *x = k - '0';
	while (1) {
		k = getchar_unlocked();
		if (k < '0' || k > '9') break;
		*x = ((*x) << 1) + ((*x) << 3) + k - '0';
	}
}
int N, M, x;
int main() {
	scanf("%d%d", &N, &M);
	int ret = N;
	for(int i = 0; i < M; i++) {
		scanf("%d", &x);
		ret = __gcd(ret, __gcd(x, N));
	}
	puts(ret == 1 ? "Yes" : "No");
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3108
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
int N, M, x;
int main() {
	scanf("%d%d", &N, &M);
	int ret = N;
	for(int i = 0; i < M; i++) {
		scanf("%d", &x);
		ret = __gcd(ret, __gcd(x, N));
	}
	puts(ret == 1 ? "Yes" : "No");
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3108
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
int N, M, x;
int main() {
	cin >> N >> M;
	int ret = N;
	for(int i = 0; i < M; i++) {
		cin >> x;
		ret = __gcd(ret, __gcd(x, N));
	}
	if(ret != 1) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3048
final_rank: 4

code_snippet: #include <iostream>
#include <algorithm>
 
using namespace std;
 
int main(){
    int n,m;
    int check;
 
    cin >> n >> m;
    check = n;
 
    while(m--){
	cin >> n;
	check = __gcd(n,check);
    }
 
    cout << (check == 1 ? "Yes" : "No") << endl;
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3088
final_rank: 5

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

int main() {
  int N, M, L; cin >> N >> M;
  
  for(int i=0; i<M; i++) {
    cin >> L;
    N = __gcd(L, N);
  }
  
  if(N == 1) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 1160
final_rank: 1

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

int main() {
  int N, M, L; cin >> N >> M;
  bool ok = M == 1;
  for(int i=0; i<M; i++) {
    cin >> L;
    if(__gcd(L, N) == 1) ok = 1;
  }
  
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}
accuracy: 0.4852941176470588
time_ms: 10
memory_kb: 1156
final_rank: 15

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

int main() {
  int N, M; cin >> N >> M;
  int L[M];
  for(int i=0; i<M; i++) cin >> L[i];
  bool ok = M == 1;
  for(int i=0; i<M-1; i++) {
    for(int j=i+1; j<M; j++) {
      if(__gcd(L[i], L[j]) == 1) ok = 1;
    }
  }
  
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}
accuracy: 0.4852941176470588
time_ms: 5400
memory_kb: 1196
final_rank: 18

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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

const string sY = "Yes", sN = "No";

int main(){
  int N,M,tmp;
  cin >> N >> M;
  rep(i,M){
    cin >> tmp;
    N = __gcd(N,tmp);
  }
  cout << ((N==1)?sY:sN) << endl;
  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 1196
final_rank: 3

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

using namespace std;

int main(){
  int n,m;
  int check;

  cin >> n >> m;
  check = n;

  while(m--){
    cin >> n;
    check = __gcd(n,check);
  }

  cout << (check == 1 ? "Yes" : "No") << endl;

  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 1160
final_rank: 1