Problem:
Problem F: Remainder Zero
Problem
整数の集合A,Bについて,次の条件を満たす整数
x
がいくつ存在するか答えよ。
A
i
mod
x
= 0 かつ
x
mod
B
j
= 0 がすべての
i
(1 ≤
i
≤ N),
j
(1 ≤
j
≤ M) について成り立つ。
(
a
mod
b
は
a
を
b
で割ったときの余りを意味する)
Input
N
M
A
1
A
2
...
A
N
B
1
B
2
...
B
M
Constraints
入力は以下の条件を満たす。
1 ≤
N
,
M
≤ 5
1 ≤
A
i
,
B
j
≤ 10
14
(1 ≤
i
≤
N
, 1 ≤
j
≤
M
)
Output
条件を満たす整数
x
がいくつ存在するか一行で出力せよ。
Sample Input 1
1 2
18
6 9
Sample Output 1
1
Sample Input 2
1 2
256
2 4
Sample Output 2
7

Submitted solutions:

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

using ll=long long;

ll modpow(ll a,ll n,ll p){
	ll r=1;
	while(n>0){
		if(n%2)r=(r*a)%p;
		n/=2;
		a=(a*a)%p;
	}
	return r;
}

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

	ll N,M;
	cin>>N>>M;
	ll G=0;
	for(int i=0;i<N;i++){
		ll A;
		cin>>A;
		G=gcd(G,A);
	}
	ll L=1;
	for(int i=0;i<M;i++){
		ll B;
		cin>>B;
		ll P=gcd(L,B);
		L/=P;
		if(L>G/B){
			cout<<0<<endl;
			return 0;
		}
		L*=B;
	}
	ll an=0;
	for(ll n=1;n*n<=G;n++){
		if(G%n==0){
			if(n%L==0)an++;
			if(n*n!=G&&(G/n)%L==0)an++;
		}
	}
	cout<<an<<endl;
}
accuracy: 1
time_ms: 20
memory_kb: 3584
final_rank: 4

code_snippet: /* -*- coding: utf-8 -*-
 *
 * 1531.cc: Problem F: Remainder Zero
 */

#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
 
using namespace std;

/* constant */

const int MAX_N = 5;
const int MAX_M = 5;
const int MAX_P = 10000000 + 50;

/* typedef */

typedef long long ll;
typedef vector<int> vi;
typedef pair<ll,int> pli;
typedef vector<pli> vpli;

/* global variables */

bool primes[MAX_P + 1];
ll as[MAX_N], bs[MAX_M];

/* subroutines */

int gen_primes(int maxp, vi &pnums) {
  fill(primes, primes + maxp + 1, true);
  primes[0] = primes[1] = false;

  int p;
  for (p = 2; p * p <= maxp; p++)
    if (primes[p]) {
      pnums.push_back(p);
      for (int q = p * p; q <= maxp; q += p) primes[q] = false;
    }
  for (; p <= maxp; p++)
    if (primes[p]) pnums.push_back(p);
  return (int)pnums.size();
}

bool prime_decomp(ll n, vi &pnums, vpli& pds) {
  pds.clear();

  int pn = pnums.size();
  for (int i = 0; i < pn; i++) {
    int pi = pnums[i];
    if ((ll)pi * pi > n) {
      if (n > 1) pds.push_back(pli(n, 1));
      return true;
    }

    if (n % pi == 0) {
      int fi = 0;
      while (n % pi == 0) n /= pi, fi++;
      pds.push_back(pli(pi, fi));
    }
  }
  return false;
}

template <typename T>
T gcd(T m, T n) {  // m >= 0, n >= 0
  if (m < n) swap(m, n);
  while (n > 0) {
    T r = m % n;
    m = n;
    n = r;
  }
  return m;
}

template <typename T>
T lcm(T m, T n) {
  return m * n / gcd<T>(m, n);
}

/* main */

int main() {
  vi pnums;
  gen_primes(MAX_P, pnums);

  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%lld", as + i);
  for (int i = 0; i < m; i++) scanf("%lld", bs + i);

  ll g = 0;
  for (int i = 0; i < n; i++) g = gcd(g, as[i]);
  //printf("g=%lld\n", g);

  for (int i = 0; i < m; i++)
    if (g % bs[i] != 0) { puts("0"); return 0; }

  ll l = 1;
  for (int i = 0; i < m; i++) l = lcm(l, bs[i]);
  //printf("l=%lld\n", l);

  ll k = g / l;
  //printf("k=%lld\n", k);

  vpli pds;
  prime_decomp(k, pnums, pds);

  ll p = 1;
  for (auto &pd: pds) p *= pd.second + 1;

  printf("%lld\n", p);
  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 18256
final_rank: 12

code_snippet: #include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){ T x; cin >> x; return (x); }
template<typename T=ll,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return x; }
template<typename T=ll,size_t N>
array<T,N> arrin(){array<T,N> x;REP(i,N){ x[i]=in<T>(); }return x;}

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

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

vector<ll> enum_div(ll n){
	vector<ll> ret;
	for(ll i=1;i*i<=n;++i){
		if(n%i==0){
			ret.push_back(i);
			if(i*i!=n){
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}

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

	auto N=in(),M=in();
	vll A=vecin(N),B=vecin(M);
	vll S;
	for(auto& x:A){
		auto D=enum_div(x);
		S.insert(S.end(),D.begin(),D.end());
	}
	sort(ALL(S));
	S.erase(unique(ALL(S)),S.end());

	ll ans=0;
	for(auto& x:S){
		bool flag=true;
		REP(i,N){
			if(A[i]%x){
				flag=false;
				break;
			}
		}
		REP(i,M){
			if(x%B[i]){
				flag=false;
				break;
			}
		}
		if(flag) ans++;
	}
	
	out(ans);
	return 0;
}
accuracy: 1
time_ms: 290
memory_kb: 3528
final_rank: 8

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


struct Info{
	Info(ll arg_num,ll arg_count,ll arg_min_mult,ll arg_max_mult){
		num = arg_num;
		count = arg_count; //N個の数のうち、いくつの数が持っているか
		min_mult = arg_min_mult;
		max_mult = arg_max_mult;
	}
	ll num,count,min_mult,max_mult;
};

ll N,M;
vector<Info> A,B;


int main(){

	ll tmp;

	scanf("%lld %lld",&N,&M);

	A.push_back(Info(1,N,1,1)); //1はAの共通約数の1つ
	B.push_back(Info(1,M,1,1));

	ll loc,tmp_count;

	//★★A:公約数が知りたいので、N個すべてに共通する素因数を求める★★
	for(int i = 0; i < N; i++){

		scanf("%lld",&tmp);

		for(ll k = 2; k*k <= tmp; k++){ //入力を素因数に分解する

			if(tmp%k != 0)continue;

			loc = -1;

			for(int a = 0; a < A.size(); a++){ //既出の数か調べる

				if(A[a].num == k){
					A[a].count += 1;
					loc = a;
					break;
				}
			}

			//次数を数える
			tmp_count = 0;

			while(tmp%k == 0){
				tmp /= k;
				tmp_count++;
			}

			if(loc == -1 && i == 0){ //初出現かつ、最初の数字

				A.push_back(Info(k,1,tmp_count,0));

			}else if(loc != -1){

				A[loc].min_mult = min(A[loc].min_mult,tmp_count); //次数のminを取る

			}else{

				//N個全部に共通する素因数でなければ意味がないのでDo nothing
			}
		}

		if(tmp == 1)continue;

		//1にならなかった場合
		loc = -1;

		for(int a = 0; a < A.size(); a++){ //既出の数か調べる

			if(A[a].num == tmp){
				A[a].count += 1;
				loc = a;
				break;
			}
		}

		if(loc != -1 || i != 0)continue;

		A.push_back(Info(tmp,1,1,1));
	}

	//★★B:最小公倍数が知りたいので、少なくとも1つに出現する素因数を洗い出し、次数のmaxを取る★★
	for(int i = 0; i < M; i++){

		scanf("%lld",&tmp);

		for(ll k = 2; k*k <= tmp; k++){ //入力を素因数に分解する

			if(tmp%k != 0)continue;

			loc = -1;

			for(int b = 0; b < B.size(); b++){ //既出の数か調べる

				if(B[b].num == k){
					loc = b;
					break;
				}
			}

			//次数を数える
			tmp_count = 0;

			while(tmp%k == 0){
				tmp /= k;
				tmp_count++;
			}

			if(loc == -1){ //初出現

				B.push_back(Info(k,1,0,tmp_count));

			}else{ //既出

				B[loc].max_mult = max(B[loc].max_mult,tmp_count); //次数のmaxを取る

			}
		}

		if(tmp == 1)continue;

		//1にならなかった場合
		loc = -1;

		for(int b = 0; b < B.size(); b++){ //既出の数か調べる

			if(B[b].num == tmp){
				loc = b;
				break;
			}
		}

		if(loc != -1)continue;

		B.push_back(Info(tmp,1,1,1));

	}

	ll ans = 1;
	bool FLG;

	//少なくともxは、Bの全ての素因数を持ち、かつ各々の次数がmax以上
	for(int i = 0; i < B.size(); i++){ //Bの少なくとも1つ出現した素因数を全探索

		FLG = false;

		for(int k = 0; k < A.size(); k++){ //Aを全探索

			if(A[k].num == B[i].num && A[k].count == N && A[k].min_mult >= B[i].max_mult){

				ans *= (A[k].min_mult-B[i].max_mult+1);

				FLG = true;
				break;
			}
		}

		if(!FLG){

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

	//Aのみにあり、Bにない素因数を探す
	for(int i = 0; i < A.size(); i++){

		if(A[i].count < N)continue;

		FLG = false;

		for(int k = 0; k < B.size(); k++){

			if(B[k].num == A[i].num){

				FLG = true;
				break;
			}
		}

		if(FLG)continue;

		ans *= (A[i].min_mult+1);
	}

	printf("%lld\n",ans);

	return 0;
}
accuracy: 1
time_ms: 720
memory_kb: 3236
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
    int n,m;
    cin >>n >>m;
    vector<ll> a(n),b(m);
    rep(i,n) cin >>a[i];
    rep(i,m) cin >>b[i];

    ll g = a[0];
    rep(i,n) g = __gcd(g,a[i]);

    ll ans = 0;

    auto check = [&](ll x){
        rep(i,m)if(x%b[i] != 0) return;
        ++ans;
    };

    for(ll i=1; i*i<=g; ++i){
        if(g%i == 0){
            check(i);
            if(g/i != i) check(g/i);
        }
    }

    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 3116
final_rank: 5

code_snippet: #include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;
using ld = long double;

long long int gcd(long long int l, long long int r) {
	if (l > r)return gcd(r, l);
	else {
		if (r%l) {
			return gcd(l, r%l);

		}
		else {
			return l;
		}
	}
}

vector<long long int> divisor(long long int n) {
	vector<long long int> res;
	for (long long int i = 1; i * i <= n; ++i) {
		if (n % i == 0) {
			res.push_back(i);
			if (i * i != n) res.push_back(n / i);
		}
	}
	sort(begin(res), end(res));
	return res;
}
int main() {
	int N,M;cin>>N>>M;
	vector<long long int>as(N),bs(M);
	for (int i = 0; i < N; ++i) {
		cin>>as[i];
	}
	for (int i = 0; i < M; ++i) {
		cin>>bs[i];
	}
	long long int ag=as[0];
	for (int i = 1; i < N; ++i) {
		ag=gcd(ag,as[i]);
	}
	bool ok=true;
	long long int bl=bs[0];
	for (int i = 1; i < M; ++i) {
		double k=bl;
		k*=bs[i];
		k/=gcd(bl,bs[i]);
		if (k > 1e15) {
			ok=false;
		}
		else {
			bl=bl/gcd(bl,bs[i])*bs[i];
		}
	}
	int ans=0;
	if (ok) {
		if (ag%bl == 0) {
			long long int tt=ag/bl;
			auto divs=divisor(tt);
			ans=divs.size();
		}
	}
	cout<<ans<<endl;
	return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 3288
final_rank: 6

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

bool overflow(unsigned long long a, unsigned long long b) {
	const unsigned long long c = a * b;
	return !(c / a == b);
}

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

	vector<unsigned long long> a(n), b(m);
	for(auto &e : a) cin >> e;
	for(auto &e : b) cin >> e;

	unsigned long long g = a[0];
	for(int i = 1; i < n; ++i) {
		g = __gcd(g, a[i]);
	}

	unsigned long long l = b[0];
	for(int i = 1; i < m; ++i) {
		l /= __gcd(l, b[i]);

		if(overflow(l, b[i])) {
			cout << 0 << endl;
			return 0;
		}

		l *= b[i];
	}

	int ans = 0;
	for(unsigned long long i = 1; i * i <= g; ++i) {
		if(g % i == 0) {
			if(i % l == 0) ++ans;
			if(i * i != g && (g / i) % l == 0) ++ans;
		}
	}

	cout << ans << endl;

	return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 1204
final_rank: 1

code_snippet: #include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>
#include <cassert>
using namespace std;

//common
typedef int  i32;
typedef long long i64,ll;
#define BR "\n"

#define ALL(c) (c).begin(),(c).end()
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))

typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef long long ll; typedef vector<long long> vl; typedef pair<long long,long long> pll; typedef vector<pair<long long,long long> > vpll;
typedef vector<string> vs; typedef long double ld;

//config
#define MODE_DEBUG
//#define INF 1<<30
//#define EPS 1e-8
//const ll MOD =100000007;

//debug
#ifdef NDEBUG
#define DUMP(x)
#define DUMPLN(x)
#define DEBUG(x)
#define DEBUGLN(x)
#define LINE()
#define LINELN()
#define CHECK(exp,act)
#define STOP(e)
#else
#define DUMP(x)  cerr << #x << " = " << (x)
#define DUMPLN(x)  DUMP(x) <<endl
#define DEBUG(x) DUMP(x) << LINE() << " " << __FILE__
#define DEBUGLN(x) DEBUG(x)<<endl
#define LINE()    cerr<< " (L" << __LINE__ << ")"
#define LINELN()    LINE()<<endl
#define CHECK(exp,act)  if(exp!=act){DUMPLN(exp);DEBUGLN(act);}
#define STOP(e)  CHECK(e,true);if(!(e)) exit(1);
#endif

template<class T> inline string toString(const vector<T>& x) {
	stringstream ss;
	REP(i,x.size()){
		if(i!=0)ss<<" ";
		ss<< x[i];
	}
	return ss.str();
}
template<class T> inline string toString(const vector<vector<T> >& map) {
	stringstream ss;
	REP(i,map.size()){
		if(i!=0)ss<<BR;
		ss<< toString(map[i]);
	}
	return ss.str();
}
template<class K,class V>  string toString(map<K,V>& x) {
	string res;stringstream ss;
	for(auto& p:x)ss<< p.first<<":" << p.second<<" ";
	return ss.str();
}

template<typename T,typename V> inline T mod(T v,V MOD){
	return (v%MOD+MOD)%MOD;
}

#define nextInt(n) scanf("%d",&n)
#define nextLong(n) scanf("%lld",&n)
#define nextDouble(n) scanf("%lf",&n)

int INF=1<<28;

template<typename T>T gcd_positive(T a, T b) { return b == 0 ? a : gcd_positive(b,a%b); }
template<typename T>T gcd(T a, T b) { return gcd_positive(abs(a), abs(b)); }
template<typename T>T lcm(T a,T b){return a*b/gcd(a,b);}

class Main{
public:	
	void run(){
		int N,M;cin >> N >> M;

		ll A;cin >> A;REP(i,N-1){ll a;cin >> a; A=gcd(A,a);}
	
		set<ll> ls;

		map<ll,int> as;
		for(ll p=2;p*p<=1e14;p++){
			int c=0;
			while(A%p==0){
				c++;A/=p;
			}
			if(c!=0){
				as[p]=c;ls.insert(p);
			}
		}
		if(A!=1) {
			as[A]=1;
			ls.insert(A);
		}

		map<ll,int> bs;
		REP(i,M){
			ll B;cin >> B;
			for(ll p=2;p*p<=1e14;p++){
				int c=0;
				while(B%p==0){
					c++;B/=p;
				}
				if(c!=0){
					bs[p]=max(bs[p],c);ls.insert(p);
				}
			}
			if(B!=1) {
				bs[B]=max(bs[B],1);
				ls.insert(B);
			}
		}
		ll res =1;
		EACH(it,ls){
			res*=max(as[*it] -bs[*it]+1,0);
		}
		cout << res<<endl;
	}
};
 int main(){
 	cout <<fixed<<setprecision(15);
	ios::sync_with_stdio(false);
 	Main().run();
 	return 0;
 }
accuracy: 1
time_ms: 530
memory_kb: 1204
final_rank: 11

code_snippet: #include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>
#include <cassert>
using namespace std;

//common
typedef int  i32;
typedef long long i64,ll;
#define BR "\n"

#define ALL(c) (c).begin(),(c).end()
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))

typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef long long ll; typedef vector<long long> vl; typedef pair<long long,long long> pll; typedef vector<pair<long long,long long> > vpll;
typedef vector<string> vs; typedef long double ld;

//config
#define MODE_DEBUG
//#define INF 1<<30
//#define EPS 1e-8
//const ll MOD =100000007;

//debug
#ifdef NDEBUG
#define DUMP(x)
#define DUMPLN(x)
#define DEBUG(x)
#define DEBUGLN(x)
#define LINE()
#define LINELN()
#define CHECK(exp,act)
#define STOP(e)
#else
#define DUMP(x)  cerr << #x << " = " << (x)
#define DUMPLN(x)  DUMP(x) <<endl
#define DEBUG(x) DUMP(x) << LINE() << " " << __FILE__
#define DEBUGLN(x) DEBUG(x)<<endl
#define LINE()    cerr<< " (L" << __LINE__ << ")"
#define LINELN()    LINE()<<endl
#define CHECK(exp,act)  if(exp!=act){DUMPLN(exp);DEBUGLN(act);}
#define STOP(e)  CHECK(e,true);if(!(e)) exit(1);
#endif

template<class T> inline string toString(const vector<T>& x) {
	stringstream ss;
	REP(i,x.size()){
		if(i!=0)ss<<" ";
		ss<< x[i];
	}
	return ss.str();
}
template<class T> inline string toString(const vector<vector<T> >& map) {
	stringstream ss;
	REP(i,map.size()){
		if(i!=0)ss<<BR;
		ss<< toString(map[i]);
	}
	return ss.str();
}
template<class K,class V>  string toString(map<K,V>& x) {
	string res;stringstream ss;
	for(auto& p:x)ss<< p.first<<":" << p.second<<" ";
	return ss.str();
}

template<typename T,typename V> inline T mod(T v,V MOD){
	return (v%MOD+MOD)%MOD;
}

#define nextInt(n) scanf("%d",&n)
#define nextLong(n) scanf("%lld",&n)
#define nextDouble(n) scanf("%lf",&n)

int INF=1<<28;

template<typename T>T gcd_positive(T a, T b) { return b == 0 ? a : gcd_positive(b,a%b); }
template<typename T>T gcd(T a, T b) { return gcd_positive(abs(a), abs(b)); }
template<typename T>T lcm(T a,T b){return a*b/gcd(a,b);}

class Main{
public:	
	void run(){
		int N,M;cin >> N >> M;

		ll A;cin >> A;REP(i,N-1){ll a;cin >> a; A=gcd(A,a);}
		ll B;cin >> B;REP(i,M-1){ll b;cin >> b; B=lcm(B,b);}

		set<ll> ls;

		map<ll,int> as;
		for(int p=2;p*p<=A;p++){
			int c=0;
			while(A%p==0){
				c++;A/=p;
			}

			if(c!=0){
				as[p]=c;ls.insert(p);
			}
		}
		if(A!=1) {
			as[A]=1;
			ls.insert(A);
		}

		map<ll,int> bs;
		for(int p=2;p*p<=B;p++){
			int c=0;
			while(B%p==0){
				c++;B/=p;
			}

			if(c!=0){
				bs[p]=c;ls.insert(p);
			}
		}
		if(B!=1) {
			bs[B]=1;
			ls.insert(B);
		}

		ll res =1;
		EACH(it,ls){
			res*=max(as[*it] -bs[*it]+1,0);
		}
		cout << res<<endl;
	}
};
 int main(){
 	cout <<fixed<<setprecision(15);
	ios::sync_with_stdio(false);
 	Main().run();
 	return 0;
 }
accuracy: 0.28846153846153844
time_ms: 30
memory_kb: 1204
final_rank: 19

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

using namespace std;

typedef long long ll;
int N,M;
ll A[5];
ll B[5];

ll gcd(ll a,ll b){
  if(b==0)return a;
  return gcd(b,a%b);
}

int main(){

  cin>>N>>M;
  for(int i=0;i<N;i++)cin>>A[i];
  for(int i=0;i<M;i++)cin>>B[i];
  ll g=A[0];
  for(int i=1;i<N;i++)g=gcd(g,A[i]);
  vector<ll> divs;
  for(ll i=1;i*i<=g;i++){
    if(g%i==0){
      divs.push_back(i);
      if(i!=g/i)divs.push_back(g/i);
    }
  }
  ll cnt=0;
  for(ll d : divs){
    bool ok=true;
    for(int i=0;i<M;i++){
      if(d%B[i]!=0){
        ok=false;
      }
    }
    if(ok)cnt++;
  }
  cout<<cnt<<endl;
  
  return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 1348
final_rank: 3

code_snippet: #include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define REP1(i,n) for(int i=1;i<=n;++i)
#define ALL(c) (c).begin(),(c).end()
typedef long long ll;
const ll ccc=10000000;
bool prime[ccc+1];
vector<ll> pr;
void makeprime(){
	ll iii,jjj;
	for(iii=0;iii<=ccc;iii++){
		prime[iii]=true;
	}
	prime[0]=false;
	prime[1]=false;
	for(iii=2;iii*iii<=ccc;iii++){
		if(prime[iii]){
			for(jjj=2*iii;jjj<=ccc;jjj+=iii){
				prime[jjj]=false;
			}
		}
	}
	for(iii=2;iii<=ccc;iii++) if(prime[iii]) pr.push_back(iii);
}
ll gcd(ll x,ll y){
	if(x<y) swap(x,y);
	ll r=1;
	while(r!=0){
		r=x%y;
		if(r==0) return y;
		x=y;
		y=r;
	}
}
int main(){
	makeprime();
	ll n,m,x,y;
	cin >> n >> m;
	cin >> x;
	rep(i,n-1){
		ll a;
		cin >> a;
		x=gcd(x,a);
	}
	cin >> y;
	rep(j,m-1){
		ll b,c;
		cin >> b;
		c=gcd(y,b);
		if((double)b/c>(double)((ll)1e+14)/y+1e-9){
			cout << 0 << endl;
			return 0;
		}
		y*=(b/c);
	}
	if(x%y!=0){
		cout << 0 << endl;
		return 0;
	}
	ll p=x/y,ans=1;
	rep(i,pr.size()){
		int cnt=1;
		while(p%pr[i]==0){
			cnt++;
			p/=pr[i];
		}
		ans*=cnt;
		if(p==1) break;
	}
	if(p>1) ans*=2;
	cout << ans << endl;
	return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 21196
final_rank: 13

code_snippet: #include <iostream>
#include <cstdio>
#include <map>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <algorithm>
#include <queue>

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()

typedef unsigned long long ull;
typedef vector<int> vi;
typedef unsigned long long ull;

ull __gcd(ull x, ull y){
    if (y == 0ULL) return x;
    else return __gcd(y, x%y);
}

int main(){
    ull n, m; cin >> n >> m;
    vector<ull> A(n), B(m);

    rep(i, A.size()) cin >> A[i];
    rep(i, B.size()) cin >> B[i];

    ull ga = A[0];
    loop(i, 1, A.size()) ga = __gcd(ga, A[i]);

    ull lb = B[0];
    loop(i, 1, B.size()) lb = lb / __gcd(lb, B[i])*B[i];
    
    ull ans;
    if (ga%lb != 0) ans = 0; 
    else {
        ull x = ga / lb;

        int end = x;

        ans = 1;
        loop(i, 2, end){
            ull e = 0;
            if (x%i == 0){
                while (x%i == 0){
                    e++;
                    x /= i;
                }
            }
            ans *= e + 1;
            if (x == 1) break;
        }
    }

    cout << ans << endl;
}
accuracy: 0.36538461538461536
time_ms: 80
memory_kb: 1184
final_rank: 18

code_snippet: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <climits>
#include <sstream>
#include <functional>
#include <complex>

using namespace std;

#define len(array)  (sizeof (array) / sizeof *(array))
#define rep(i, s, e) for(int i = s;i < e;i++)
#define Rep(i, e) for(int i = 0;i < e;i++)
#define rrep(i, e, s) for(int i = e;s <= i;i--)
#define Rrep(i, e) for(int i = e;0 <= i;i--)
#define mrep(i, e, t1, t2) for(map<t1, t2>::iterator i = e.begin(); i != e.end(); i++)
#define vrange(v) v.begin(), v.end()
#define vrrange(v) v.rbegin(), v.rend()
#define vsort(v) sort(vrange(v))
#define vrsort(v) sort(vrrange(v))
#define arange(a) a, a + len(a)
#define asort(a) sort(arange(a))
#define arsort(a, t) sort(arange(a), greater<t>())
#define afill(a, v) fill(arange(a), v)
#define afill2(a, v, t) fill((t *)a, (t *)(a + len(a)), v)
#define fmax(a, b) (a < b? b : a)
#define fmin(a, b) (a > b? b : a)
#define fabs(a) (a < 0? -a : a)
#define pb push_back
#define rg(e, s, t) s <= e && e < t
#define PQDecl(name, tp) priority_queue< tp, vector<tp>, greater<tp> > name;
//#define X real()
//#define Y imag()
//typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
//typedef complex<double> p;
const int INF = (int)2e9;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-10;
//const int dx[] = {1, -1, 0, 0, 1, -1, -1, 1};
//const int dy[] = {0, 0, 1, -1, -1, -1, 1, 1};
//const ll weight[] = {1e0,1e1,1e2,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13};
#define MAX_N 1000

#define MAX_PRIMES 10000002
bool bPrimes[MAX_PRIMES];
vector<int> primes;

void makePrimes(){
  afill(bPrimes, true);
  bPrimes[0] = bPrimes[1] = false;
  rep(i, 2, MAX_PRIMES){
	if(bPrimes[i]){
	  primes.push_back(i);
	  for(int j = 2*i; j < MAX_PRIMES; j += i) bPrimes[j] = false;
	}
  }
}

ll gcd(ll a, ll b) {
  if( a < b ) swap( a, b );
  return b != 0 ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

ll lpow(ll n, ll p){
  ll ans = 1, ln = n;
  if(p <= 0) return 1;
  while(p != 0){
	if((p & 1) == 1) ans = ans*ln;
	ln = ln * ln;
	p = p >> 1;
  }
  return ans;
}

void doIt(){
  makePrimes();
  // cout << primes.size() << endl;
  int n, m, p[700000], ptmp[700000];
  ll a, b, g = -1;
  map<ll, int> mmap;
  cin >> n >> m;
  Rep(i, n){
    cin >> a;
    if(g == -1) g = a;
    else g = gcd(g, a);
  }

  afill(p, 0);
  Rep(i, m){
    cin >> b;
    afill(ptmp, 0);
    Rep(j, primes.size()){
      while(b % primes[j] == 0){
        b /= primes[j];
        ptmp[j]++;
      }
      p[j] = max(p[j], ptmp[j]);
    }
    if(b != 1) mmap[b]++;
  }
  bool bOK = true;
  ll ans = 1;
  Rep(i, primes.size()){
    int count = 0;
    while(g % primes[i] == 0){
      g /= primes[i];
      count++;
    }
    int diff = count - p[i];
    if(diff >= 0) ans *= diff + 1;
    else bOK = false;
    // if(diff) printf("diff = %d, i = %d\n", diff, i);
  }
  if(g != 1){
    if(mmap.count(g) != 0){
      mmap[g] = 0;
    }
    else{
      ans *= 2;
    }
  }
  mrep(it, mmap, ll, int){
    if((*it).second){
      bOK = false;
    }
  }
  // printf("bOK = %d\n", bOK);
  if(bOK){
    cout << ans << endl;
  }
  else{
    cout << 0 << endl;
  }
}

int main() {
  doIt();
  return 0;
}
accuracy: 1
time_ms: 140
memory_kb: 20464
final_rank: 15

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

using namespace std;
typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<ll> a(n), b(m);
	for(int i = 0; i < n; ++i){ cin >> a[i]; }
	for(int i = 0; i < m; ++i){ cin >> b[i]; }
	ll x = a[0], y = 1;
	for(int i = 0; i < n; ++i){ x = __gcd(x, a[i]); }
	for(int i = 0; i < m; ++i){
		const ll g = __gcd(y, b[i]);
		const ll t = b[i] / g;
		if(__int128(t) * y > x){
			y = -1;
			break;
		}
		y *= t;
	}
	if(y < 0){
		cout << 0 << endl;
	}else{
        int answer = 0;
        for(ll i = 1; i * i <= x; ++i){
            if(x % i == 0){
                if(i % y == 0){ ++answer; }
                if(i * i != x && (x / i) % y == 0){ ++answer; }
            }
        }
		cout << answer << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 1204
final_rank: 2

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

using namespace std;
typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<ll> a(n), b(m);
	for(int i = 0; i < n; ++i){ cin >> a[i]; }
	for(int i = 0; i < m; ++i){ cin >> b[i]; }
	ll x = a[0], y = 1;
	for(int i = 0; i < n; ++i){ x = __gcd(x, a[i]); }
	for(int i = 0; i < m; ++i){
		const ll g = __gcd(y, b[i]);
		const ll t = b[i] / g;
		if(__int128(t) * y > x){
			y = -1;
			break;
		}
		y *= t;
	}
	if(y < 0){
		cout << 0 << endl;
	}else{
		ll l = 0, r = 1000000000;
        while(l < r){
            const ll c = l + (r - l) / 2;
            if(c * c < x){
                l = c + 1;
            }else{
                r = c;
            }
        }
        int answer = 0;
        for(ll i = 1; i <= l; ++i){
            if(x % i == 0){
                if(i % y == 0){ ++answer; }
                if(i * i != x && x / i % y == 0){ ++answer; }
            }
        }
		cout << answer << endl;
	}
	return 0;
}
accuracy: 0.9038461538461539
time_ms: 90
memory_kb: 1204
final_rank: 17

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

using namespace std;
typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<ll> a(n), b(m);
	for(int i = 0; i < n; ++i){ cin >> a[i]; }
	for(int i = 0; i < m; ++i){ cin >> b[i]; }
	ll x = a[0], y = 1;
	for(int i = 0; i < n; ++i){ x = __gcd(x, a[i]); }
	for(int i = 0; i < m; ++i){
		const ll g = __gcd(y, b[i]);
		const ll t = b[i] / g;
		if(y > x / t){
			y = -1;
			break;
		}else{
			y = y * t;
		}
	}
	if(y < 0 || x % y != 0){
		cout << 0 << endl;
	}else{
		ll l = 0, r = 1000000000;
		while(l < r){
			const ll c = l + (r - l) / 2;
			if(c * c < x){
				l = c + 1;
			}else{
				r = c;
			}
		}
		int answer = 0;
		for(ll i = 1; i <= l; ++i){
			if(x % i == 0){
				if(i % y == 0){ ++answer; }
				if(i * i != x && x / i % y == 0){ ++answer; }
			}
		}
		cout << answer << endl;
	}
	return 0;
}
accuracy: 0.9038461538461539
time_ms: 80
memory_kb: 1208
final_rank: 16

code_snippet: #include <iostream>
#include <map>
#include <set>
using namespace std;

long long A[10],B[10];
int main(){
	int N,M;
	cin >> N >> M;
	for(int i = 0 ; i < N ; i++) cin >> A[i];
	for(int i = 0 ; i < M ; i++) cin >> B[i];

	map<long long,int> o;
	for(int i = 0 ; i < N ; i++){
		for(long long j = 1 ; j*j <= A[i] ; j++){
				if( A[i] % j == 0 ){
				long long a = A[i] / j;
				long long b = j;
				int af = 1;
				int bf = 1;
				for(int k = 0 ; k < M ; k++){
					if( a%B[k] != 0 ) af = 0;
					if( b%B[k] != 0 ) bf = 0;
				}
				if( af ) o[a] |= (1<<i);
				if( bf ) o[b] |= (1<<i);
			}
		}
	}
	int ans = 0;
	for( map<long long,int>::iterator it = o.begin(); it != o.end(); ++it){
		if( it->second == (1<<N)-1 ) ans++;
	}
	cout << ans << endl;
	
	
}
accuracy: 1
time_ms: 420
memory_kb: 1844
final_rank: 10

code_snippet: #include <iostream>
#include <map>
#include <set>
using namespace std;

long long A[10],B[10];
int main(){
	int N,M;
	cin >> N >> M;
	for(int i = 0 ; i < N ; i++) cin >> A[i];
	for(int i = 0 ; i < M ; i++) cin >> B[i];

	map<long long,int> o;
	for(int i = 0 ; i < N ; i++){
		for(long long j = 1 ; j*j <= A[i] ; j++){
				if( A[i] % j == 0 ){
				int a = A[i] / j;
				int b = j;
				int af = 1;
				int bf = 1;
				for(int k = 0 ; k < M ; k++){
					if( a%B[k] != 0 ) af = 0;
					if( b%B[k] != 0 ) bf = 0;
				}
				if( af ) o[a] |= (1<<i);
				if( bf ) o[b] |= (1<<i);
			}
		}
	}
	int ans = 0;
	for( map<long long,int>::iterator it = o.begin(); it != o.end(); ++it){
		if( it->second == (1<<N)-1 ) ans++;
	}
	cout << ans << endl;
	
	
}
accuracy: 0.23076923076923078
time_ms: 60
memory_kb: 1208
final_rank: 20

code_snippet: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>
#include <bitset>

#ifdef LOCAL
#include "local.h"
#endif

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define clr(a, x) memset(a, x, sizeof(a))
#define sz(a) ((int)(a).size())
#define mp(a, b) make_pair(a, b)
#define ten(n) ((long long)(1e##n))

template <typename T, typename U> void upmin(T& a, const U& b) { a = min<T>(a, b); }
template <typename T, typename U> void upmax(T& a, const U& b) { a = max<T>(a, b); }
template <typename T> void uniq(T& a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }
template <class T> string to_s(const T& a) { ostringstream os; os << a; return os.str(); }
template <class T> T to_T(const string& s) { istringstream is(s); T res; is >> res; return res; }
void fast_io() { cin.tie(0); ios::sync_with_stdio(false); }
bool in_rect(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; }

typedef long long ll;
typedef pair<int, int> pint;

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

template <class T>
vector<T> divisors(T n)
{
    vector<T> res;
    for (T i = 1; i * i <= n; ++i)
    {
        if (n % i == 0)
        {
            res.push_back(i);
            if (i != n / i)
                res.push_back(n / i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

ll gcd(ll a, ll b) { return b ? __gcd(b, a % b) : a; }
int main()
{
    int n, m;
    cin >> n >> m;
    vector<ll> a(n), b(m);
    rep(i, n)
        cin >> a[i];
    rep(i, m)
        cin >> b[i];

    vector<ll> cand;
    rep(i, a.size())
    {
        vector<ll> divs = divisors(a[i]);
        rep(di, divs.size())
        {
            ll div = divs[di];
            bool ok = true;
            rep(j, a.size())
            {
                if (a[j] % div != 0)
                {
                    ok = false;
                    break;
                }
            }
            if (ok)
                cand.push_back(div);
        }
    }
    uniq(cand);

    int res = 0;
    rep(ci, cand.size())
    {
        ll x = cand[ci];
        bool ok = true;
        rep(i, b.size())
        {
            if (x % b[i] != 0)
            {
                ok = false;
                break;
            }
        }
        if (ok)
            ++res;
    }
    cout << res << endl;
}
accuracy: 1
time_ms: 400
memory_kb: 1376
final_rank: 9

code_snippet: #define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef long long ll; typedef vector<long long> vl; typedef pair<long long,long long> pll; typedef vector<pair<long long,long long> > vpll;
typedef vector<string> vs; typedef long double ld;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

vector<bool> isprime;
vector<int> primes;
void sieve(int n){
	if((int)isprime.size() >= n+1) return;
	isprime.assign(n+1, true);
	isprime[0] = isprime[1] = false;
	int sqrtn = (int)(sqrt(n * 1.) + .5);
	for(int i = 2; i <= sqrtn; i ++) if(isprime[i]) {
		for(int j = i * i; j <= n; j += i)
			isprime[j] = false;
	}
	primes.clear();
	for(int i = 2; i <= n; i ++) if(isprime[i])
		primes.push_back(i);
}

typedef vector<pair<ll,int> > Factors;
void primeFactors(ll x, Factors &out_v) {
	out_v.clear();
	int sqrtx = (int)(sqrt(x*1.) + 10.5);
	sieve(sqrtx);
	each(p, primes) {
		if(*p > sqrtx) break;
		if(x % *p == 0) {
			int t = 1;
			x /= *p;
			while(x % *p == 0) {
				t ++;
				x /= *p;
			}
			out_v.push_back(make_pair(*p, t));
		}
	}
	if(x != 1) out_v.push_back(make_pair(x, 1));
}

template<typename Op> inline Factors combineFactors(Op op, int id, const Factors &a, const Factors &b) {
	Factors c;
	int an = a.size(), bn = b.size();
	int ai = 0, bi = 0;
	while(ai < an || bi < bn) {
		typename Factors::value_type::first_type p; int q;
		if(ai < an && (bi >= bn || a[ai].first < b[bi].first)) {
			p = a[ai].first, q = op(a[ai].second, id);
			ai ++;
		}else if(bi < bn && (ai >= an || a[ai].first > b[bi].first)) {
			p = b[bi].first, q = op(id, b[bi].second);
			bi ++;
		}else {
			p = a[ai].first, q = op(a[ai].second, b[bi].second);
			ai ++, bi ++;
		}
		if(q != 0) c.push_back(mp(p, q));
	}
	return c;
}

Factors gcdFactors(const Factors &a, const Factors &b) {
	return combineFactors<const int&(*)(const int&,const int&)>(std::min<int>, 0, a, b);
}
Factors lcmFactors(const Factors &a, const Factors &b) {
	return combineFactors<const int&(*)(const int&,const int&)>(std::max<int>, 0, a, b);
}

int main() {
	sieve((int)1e7+20);
	int N, M;
	scanf("%d%d", &N, &M);
	Factors g, l;
	rep(i, N) {
		ll A;
		scanf("%lld", &A);
		Factors fs;
		primeFactors(A, fs);
		if(i == 0) g = fs;
		else g = gcdFactors(g, fs);
	}
	rep(i, M) {
		ll B;
		scanf("%lld", &B);
		Factors fs;
		primeFactors(B, fs);
		l = lcmFactors(l, fs);
	}
	map<ll,int> ga(all(g)), la(all(l));
	set<ll> ps;
	each(i, ga) ps.insert(i->first);
	each(i, la) ps.insert(i->first);
	ll ans = 1;
	each(i, ps) {
		ll upper = ga[*i], lower = la[*i];
		if(lower > upper) ans = 0;
		else ans *= upper - lower + 1;
	}
	printf("%lld\n", ans);
	return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 8404
final_rank: 7