/*
 Julia M.(aka Andrei Konstantinovich)
 */
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
#define x first
#define y second
#define ll long long
#define pii pair<ll, ll>
#define ld long double
const int MN = 1e5 + 111, MT = 7001;
bitset<MT> r[MN];
bitset<MT> prep[MT], prepmask[MT];
int sq[MT];

int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    for (int i = 1; i < MT; ++i)
    {
        for (int j = i; j < MT; j += i)
        {
            prep[j][i] = 1;
        }
    }
    for (int i = 2; i * i < MT; i++)
    {
        sq[i * i] = 1;
    }

    for (int i = 1; i < MT; ++i)
    {
        for (int j = i; j < MT; j += i)
        {
            if (sq[j / i])
                continue;
            prepmask[i][j] = 1;
        }
    }

    int n, q;
    cin >> n >> q;
    for (int i = 0; i < q; ++i)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int x, v;
            cin >> x >> v;
            x--;
            r[x] = prep[v];
        }
        else if (t == 2)
        {
            int x, y, z;
            cin >> x >> y >> z;
            x--;
            y--;
            z--;
            r[x] = r[y] ^ r[z];
        }
        else if (t == 3)
        {
            int x, y, z;
            cin >> x >> y >> z;
            x--;
            y--;
            z--;
            r[x] = r[y] & r[z];
        }
        else
        {
            int x, v;
            cin >> x >> v;
            x--;
            cout << (((r[x] & prepmask[v]).count()) & 1);
        }
    }
}


// And in the end, the love you take is equal to the love you make.
//                      Paul McCartney (the Beatles). The End. Abbey Road.

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

using LL = long long;

namespace _buff {

const size_t BUFF = 1 << 19;
char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
char getc() {
  if (ib == ie) {
    ib = ibuf;
    ie = ibuf + fread(ibuf, 1, BUFF, stdin);
  }
  return ib == ie ? -1 : *ib++;
}

}

LL read() {
  using namespace _buff;
  LL ret = 0;
  bool pos = true;
  char c = getc();
  for (; (c < '0' || c > '9') && c != '-'; c = getc()) {
    assert(~c);
  }
  if (c == '-') {
    pos = false;
    c = getc();
  }
  for (; c >= '0' && c <= '9'; c = getc()) {
    ret = (ret << 3) + (ret << 1) + (c ^ 48);
  }
  return pos ? ret : -ret;
}

const size_t N = 1e5 + 5;
const size_t M = 7e3 + 5;

bitset<M> b[N], c1[M], c2[M];

void prep() {
  bitset<M> npr, mu;
  vector<int> pri;
  mu.set(1);
  for (int i = 2; i < M; ++i) {
    if (!npr[i]) {
      mu.set(i);
      pri.emplace_back(i);
    }
    for (int j : pri) {
      int k = i * j;
      if (k >= M) break;
      npr[k] = true;
      if (i % j == 0) break;
      mu[k] = mu[i];
    }
  }
  for (int i = 1; i < M; ++i) {
    for (int j = i; j < M; j += i) {
      c1[j].set(i);
    }
  }
  for (int i = 1; i < M; ++i) {
    for (int j = i; j < M; j += i) {
      if (mu[j / i]) {
        c2[i].set(j);
      }
    }
  }
}

int main() {
  prep();
  read();
  int q = read();
  while (q--) {
    int typ = read();
    if (typ == 1) {
      int x = read(), v = read();
      b[x] = c1[v];
    } else if (typ == 2) {
      int x = read(), y = read(), z = read();
      b[x] = b[y] ^ b[z];
    } else if (typ == 3) {
      int x = read(), y = read(), z = read();
      b[x] = b[y] & b[z];
    } else {
      int x = read(), v = read();
      putchar('0' + ((b[x] & c2[v]).count() & 1));
    }
  }
  return 0;
}


// And in the end, the love you take is equal to the love you make.
//                      Paul McCartney (the Beatles). The End. Abbey Road.

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

using LL = long long;

namespace _buff {

const size_t BUFF = 1 << 19;
char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
char getc() {
  if (ib == ie) {
    ib = ibuf;
    ie = ibuf + fread(ibuf, 1, BUFF, stdin);
  }
  return ib == ie ? -1 : *ib++;
}

}

LL read() {
  using namespace _buff;
  LL ret = 0;
  bool pos = true;
  char c = getc();
  for (; (c < '0' || c > '9') && c != '-'; c = getc()) {
    assert(~c);
  }
  if (c == '-') {
    pos = false;
    c = getc();
  }
  for (; c >= '0' && c <= '9'; c = getc()) {
    ret = (ret << 3) + (ret << 1) + (c ^ 48);
  }
  return pos ? ret : -ret;
}

const size_t N = 1e5 + 5;
const size_t M = 7e3 + 5;

bitset<N> b[N], c1[M], c2[M];

void prep() {
  bitset<M> npr, mu;
  vector<int> pri;
  mu.set(1);
  for (int i = 2; i < M; ++i) {
    if (!npr[i]) {
      mu.set(i);
      pri.emplace_back(i);
    }
    for (int j : pri) {
      int k = i * j;
      if (k >= M) break;
      npr[k] = true;
      if (i % j == 0) break;
      mu[k] = mu[i];
    }
  }
  for (int i = 1; i < M; ++i) {
    for (int j = i; j < M; j += i) {
      c1[j].set(i);
    }
  }
  for (int i = 1; i < M; ++i) {
    for (int j = i; j < M; j += i) {
      if (mu[j / i]) {
        c2[i].set(j);
      }
    }
  }
}

int main() {
  prep();
  read();
  int q = read();
  while (q--) {
    int typ = read();
    if (typ == 1) {
      int x = read(), v = read();
      b[x] = c1[v];
    } else if (typ == 2) {
      int x = read(), y = read(), z = read();
      b[x] = b[y] ^ b[z];
    } else if (typ == 3) {
      int x = read(), y = read(), z = read();
      b[x] = b[y] & b[z];
    } else {
      int x = read(), v = read();
      putchar('0' + ((b[x] & c2[v]).count() & 1));
    }
  }
  return 0;
}


// Author: Tyler Wang

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <optional>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string_view>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

using namespace std;

template <class C>
constexpr auto ssize(const C& c)
    -> std::common_type_t<std::ptrdiff_t,
                          std::make_signed_t<decltype(c.size())>> {
  using R = std::common_type_t<std::ptrdiff_t,
                               std::make_signed_t<decltype(c.size())>>;
  return (R)c.size();
}

template <class T, std::ptrdiff_t N>
constexpr std::ptrdiff_t ssize(const T (&)[N]) noexcept {
  return N;
}

template <typename T>
constexpr std::enable_if_t<std::is_unsigned_v<T>, bool> has_single_bit(
    T x) noexcept {
  return x != 0 && (x & (x - 1)) == 0;
}

template <typename T>
constexpr std::enable_if_t<std::is_unsigned_v<T>, int> countl_zero(
    T x) noexcept {
  if constexpr (sizeof(T) <= sizeof(unsigned)) {
    return __builtin_clz(x) - (std::numeric_limits<unsigned>::digits -
                               std::numeric_limits<T>::digits);
  } else if constexpr (sizeof(T) <= sizeof(unsigned long)) {
    return __builtin_clzl(x) - (std::numeric_limits<unsigned long>::digits -
                                std::numeric_limits<T>::digits);
  } else {
    static_assert(sizeof(T) <= sizeof(unsigned long long));
    return __builtin_clzll(x) -
           (std::numeric_limits<unsigned long long>::digits -
            std::numeric_limits<T>::digits);
  }
}

template <typename T>
constexpr std::enable_if_t<std::is_unsigned_v<T>, int> countr_zero(
    T x) noexcept {
  if constexpr (sizeof(T) <= sizeof(unsigned)) {
    return __builtin_ctz(x);
  } else if constexpr (sizeof(T) <= sizeof(unsigned long)) {
    return __builtin_ctzl(x);
  } else {
    static_assert(sizeof(T) <= sizeof(unsigned long long));
    return __builtin_ctzll(x);
  }
}

template <typename T>
constexpr std::enable_if_t<std::is_unsigned_v<T>, int> popcount(T x) noexcept {
  if constexpr (sizeof(T) <= sizeof(unsigned)) {
    return __builtin_popcount(x);
  } else if constexpr (sizeof(T) <= sizeof(unsigned long long)) {
    return __builtin_popcountl(x);
  } else {
    static_assert(sizeof(T) <= sizeof(unsigned long long));
    return __builtin_popcountll(x);
  }
}

template <typename T>
constexpr std::enable_if_t<std::is_unsigned_v<T>, T> bit_width(T x) noexcept {
  return (T)(std::numeric_limits<T>::digits - countl_zero(x));
}

template <typename T>
constexpr std::enable_if_t<std::is_unsigned_v<T>, T> bit_ceil(T x) noexcept {
  return (T)(x <= 1 ? 1 : (T)1 << bit_width((T)(x - 1)));
}

template <typename T>
constexpr std::enable_if_t<std::is_unsigned_v<T>, T> bit_floor(T x) noexcept {
  return (T)(x == 0 ? 0 : (T)1 << (bit_width(x) - 1));
}

#if defined(__GNUC__) && !defined(__clang__)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

template <typename Key, typename Compare = std::less<Key>,
          typename Allocator = std::allocator<Key>>
using ordered_set =
    __gnu_pbds::tree<Key, __gnu_pbds::null_type, Compare,
                     __gnu_pbds::rb_tree_tag,
                     __gnu_pbds::tree_order_statistics_node_update, Allocator>;

template <typename Key, typename T, typename Compare = std::less<Key>,
          typename Allocator = std::allocator<std::pair<const Key, T>>>
using ordered_map =
    __gnu_pbds::tree<Key, T, Compare, __gnu_pbds::rb_tree_tag,
                     __gnu_pbds::tree_order_statistics_node_update, Allocator>;

#endif

template <typename Fun>
class y_combinator_result {
 public:
  template <typename T>
  explicit y_combinator_result(T&& fun) : fun_(std::forward<T>(fun)) {}

  template <typename... Args>
  decltype(auto) operator()(Args&&... args) {
    return fun_(std::ref(*this), std::forward<Args>(args)...);
  }

 private:
  Fun fun_;
};

template <typename Fun>
decltype(auto) y_combinator(Fun&& fun) {
  return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}

template <typename T>
std::ostream& operator<<(std::ostream& os, const std::optional<T>& opt);

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p);

template <typename... Ts>
std::ostream& operator<<(std::ostream& os, const std::tuple<Ts...>& t);

template <typename Container,
          std::enable_if_t<!std::is_convertible_v<Container, std::string_view>,
                           typename Container::const_iterator>* = nullptr>
std::ostream& operator<<(std::ostream& os, const Container& c);

template <typename ContainerAdaptor,
          typename ContainerAdaptor::container_type* = nullptr>
std::ostream& operator<<(std::ostream& os, const ContainerAdaptor& a);

template <typename T>
std::ostream& operator<<(std::ostream& os, const std::optional<T>& opt) {
  return opt ? os << *opt : os << "nullopt";
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p) {
  return os << '{' << p.first << ", " << p.second << '}';
}

template <typename... Ts>
std::ostream& operator<<(std::ostream& os, const std::tuple<Ts...>& t) {
  return std::apply(
      [&os](const Ts&... args) -> std::ostream& {
        os << '{';
        int i = 0;
        ((os << (i++ == 0 ? "" : ", ") << args), ...);
        return os << '}';
      },
      t);
}

template <typename Container,
          std::enable_if_t<!std::is_convertible_v<Container, std::string_view>,
                           typename Container::const_iterator>*>
std::ostream& operator<<(std::ostream& os, const Container& c) {
  os << '{';
  for (auto it = c.begin(); it != c.end(); ++it) {
    os << (it == c.begin() ? "" : ", ") << *it;
  }
  return os << '}';
}

template <typename ContainerAdaptor, typename ContainerAdaptor::container_type*>
std::ostream& operator<<(std::ostream& os, const ContainerAdaptor& a) {
  class subadaptor : public ContainerAdaptor {
   public:
    const auto& c() const { return ContainerAdaptor::c; }
  };
  return os << static_cast<const subadaptor&>(a).c();
}

namespace detail {

template <typename... Ts>
void print(std::ostream& os, int line, std::string_view keys,
           const Ts&... vals) {
  if constexpr (sizeof...(Ts) == 0) {
    os << "  " << line << " |" << std::endl;
  } else {
    std::vector<std::string_view> key_list;
    key_list.reserve(sizeof...(Ts));
    int start = 0, paren = 0;
    for (int i = 0; i < (int)keys.size(); ++i) {
      switch (keys[i]) {
        case '(':
        case '[':
        case '{':
          ++paren;
          break;
        case ')':
        case ']':
        case '}':
          --paren;
          break;
        case ',':
          if (paren == 0) {
            key_list.push_back(keys.substr(start, i - start));
            start = i;
          }
          break;
      }
    }
    key_list.push_back(keys.substr(start));
    assert(key_list.size() == sizeof...(Ts));
    os << "  " << line << " | ";
    int i = 0;
    ((os << key_list[i++] << " = " << vals), ...);
    os << std::endl;
  }
}

}  // namespace detail

#ifdef TYLER
#define debug(...) \
  detail::print(std::cerr, __LINE__, #__VA_ARGS__ __VA_OPT__(, ) __VA_ARGS__)
#else
#define debug(...) ((void)0)
#endif

int main() {
  auto start_time = std::chrono::steady_clock::now();
  std::mt19937 thanos(
      (std::uint_fast32_t)start_time.time_since_epoch().count());
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.precision(24);
  constexpr int N = 7007;
  vector<bitset<N>> divs(N);
  for (int i = 1; i < N; ++i) {
    for (int j = 1; j <= i; ++j) {
      if (i % j == 0) {
        divs[i][j] = true;
      }
    }
  }
  vector<bool> sqfree(N, true);
  for (int i = 2; i * i < N; ++i) {
    for (int j = i * i; j < N; j += i * i) {
      sqfree[j] = false;
    }
  }
  vector<bitset<N>> muls(N);
  for (int i = 1; i < N; ++i) {
    for (int j = i; j < N; j += i) {
      if (sqfree[j / i]) {
        muls[i][j] = true;
      }
    }
  }
  int n, q;
  cin >> n >> q;
  vector<bitset<N>> sets(n);
  while (q--) {
    int type;
    cin >> type;
    if (type == 1) {
      int x, v;
      cin >> x >> v;
      --x;
      sets[x] = divs[v];
    } else if (type == 2) {
      int x, y, z;
      cin >> x >> y >> z;
      --x, --y, --z;
      sets[x] = sets[y] ^ sets[z];
    } else if (type == 3) {
      int x, y, z;
      cin >> x >> y >> z;
      --x, --y, --z;
      sets[x] = sets[y] & sets[z];
    } else if (type == 4) {
      int x, v;
      cin >> x >> v;
      --x;
      cout << ((sets[x] & muls[v]).count() & 1);
    } else {
      assert(false);
    }
  }
  cout << '\n';
  return 0;
}


// Author: Tyler Wang

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <optional>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string_view>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

using namespace std;

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p) {
  return os << '{' << p.first << ", " << p.second << '}';
}

template <typename Container, typename = typename Container::const_iterator,
          typename = typename std::enable_if_t<
              !std::is_same_v<Container, std::string> &&
              !std::is_same_v<Container, std::string_view>>>
std::ostream& operator<<(std::ostream& os, const Container& x) {
  os << '{';
  for (auto it = x.begin(); it != x.end(); ++it) {
    if (it != x.begin()) {
      os << ", ";
    }
    os << *it;
  }
  return os << '}';
}

template <typename T>
void debug_impl(std::string_view name, const T& val) {
  std::cerr << name << " = " << val << '\n';
}

template <typename T1, typename... Ts>
void debug_impl(std::string_view names, const T1& val1, const Ts&... vals) {
  std::size_t comma = names.find(',');
  std::cerr << names.substr(0, comma) << " = " << val1 << ',';
  debug_impl(names.substr(comma + 1), vals...);
}

#ifdef TYLER
#define debug(...) debug_impl(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) ((void)0)
#endif

int main() {
  std::mt19937 rng(
      std::chrono::high_resolution_clock::now().time_since_epoch().count());
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cerr << std::boolalpha;
  int n, q;
  cin >> n >> q;
  vector<set<int>> st(n);
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      int x, v;
      cin >> x >> v;
      --x;
      st[x] = {v};
    } else if (t == 2) {
      int x, y, z;
      cin >> x >> y >> z;
      --x, --y, --z;
      set<int> res;
      for (int i : st[y]) {
        if (st[z].find(i) == st[z].end()) {
          res.insert(i);
        }
      }
      for (int i : st[z]) {
        if (st[y].find(i) == st[y].end()) {
          res.insert(i);
        }
      }
      st[x] = move(res);
    } else if (t == 3) {
      int x, y, z;
      cin >> x >> y >> z;
      --x, --y, --z;
      set<int> res;
      for (int i : st[y]) {
        for (int j : st[z]) {
          int g = gcd(i, j);
          if (res.find(g) == res.end()) {
            res.insert(g);
          } else {
            res.erase(g);
          }
        }
      }
      st[x] = move(res);
    } else {
      int x, v;
      cin >> x >> v;
      --x;
      cout << (st[x].find(v) != st[x].end());
    }
  }
  cout << '\n';
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define INF 1000000005
#define LINF 1000000000000000005

int n,m,x,y,z,v,t,g[7005][7005],s[7005];

bitset <7005> a[100005],p[7005],q[7005];

string ans;

bool sqrfree(int x){
    for(int i=2;i*i<=x;i++){
        int t=0;
        while(x%i==0){
            t++;
            x/=i;
        }
        if(t>1) return 0;
    }
    return 1;
}

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n >> m;
    for(int i=1;i<=7000;i++){
        if(sqrfree(i)) s[i]=1;
    }
    for(int i=1;i<=7000;i++){
        for(int j=1;i*j<=7000;j++){
            p[i*j][i]=1;
            if(s[j]) q[i][i*j]=1;
        }
    }
    for(int i=1;i<=m;i++){
        cin >> t;
        if(t==1){
            cin >> x >> v;
            a[x]=p[v];
        }
        else if(t==2){
            cin >> x >> y >> z;
            a[x]=a[y]^a[z];
        }
        else if(t==3){
            cin >> x >> y >> z;
            a[x]=a[y]&a[z];
        }
        else{
            cin >> x >> v;
            if((a[x]&q[v]).count()%2) ans+='1';
            else ans+='0';
        }
    }
    cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define INF 1000000005
#define LINF 1000000000000000005

ll n,k,mod=1e9+7,dp[60][100005],ans=1,inv[60];

ll pwr(ll a, ll p){
    if(p==0) return 1;
    ll t=pwr(a,p/2);
    t=t*t%mod;
    if(p%2) t=t*a%mod;
    return t;
}

ll brut(ll n, ll k){
    if(n==1) return 1;
    if(k==0) return n%mod;
    ll a=0,b=0,s=sqrt(n);
    for(ll i=1;i<=s;i++){
        if(n%i==0){
            a+=brut(i,k-1); b++;
            a%=mod; b%=mod;
            if(i*i!=n){
                a+=brut(n/i,k-1); b++;
                a%=mod; b%=mod;
            }
        }
    }
    return a*pwr(b,mod-2)%mod;
}

ll sol(ll n, ll k){
    ans=1; ll N=n;
    for(ll p=2;p*p<=N;p++){
        if(n%p) continue;
        int q=0;
        while(n%p==0){
            q++;
            n/=p;
        }
        ll f=1;
        for(int i=0;i<=q;i++){
            dp[i][0]=f;
            f*=p; f%=mod;
        }
        for(int i=0;i<=k;i++){
            dp[0][i]=1;
        }
        for(int i=1;i<=q;i++){
            for(int j=1;j<=k;j++){
                dp[i][j]=(((dp[i][j-1]+i*dp[i-1][j])%mod)*inv[i+1])%mod;
            }
        }
        ans*=dp[q][k];
        ans%=mod;
    }
    if(n!=1){
        ll f=1;
        for(int i=1;i<=k;i++) f*=2,f%=mod;
        ans*=(n+f-1)%mod*pwr(f,mod-2)%mod;
        ans%=mod;
    }
    return ans;
}

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n >> k;
    for(int i=1;i<=59;i++) inv[i]=pwr(i,mod-2);
    /*for(int i=1;i<=1000000;i++){
        if(i%100==0) cout << brut(i,5) << ' ' << sol(i,5) << '\n';
        if(brut(i,5)!=sol(i,5)) cout << "! " << brut(i,5) << ' ' << sol(i,5) << '\n';
    }*/
    cout << sol(n,k) << '\n';
    //cout << brut(n,k) << '\n';
}


#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define INF 1000000005
#define LINF 1000000000000000005

int n,m,x,y,z,v,t,s[7005];

bitset <7005> a[100005],p[7005],q[7005];

string ans;

bool sqrfree(int x){
    for(int i=2;i*i<=x;i++){
        int t=0;
        while(x%i==0){
            t++;
            x/=i;
        }
        if(t>1) return 0;
    }
    return 1;
}

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n >> m;
    for(int i=1;i<=7000;i++){
        if(sqrfree(i)) s[i]=1;
    }
    for(int i=1;i<=7000;i++){
        for(int j=1;i*j<=7000;j++){
            p[i*j][i]=1;
            if(s[j]) q[i][i*j]=1;
        }
    }
    for(int i=1;i<=m;i++){
        cin >> t;
        if(t==1){
            cin >> x >> v;
            a[x]=p[v];
        }
        else if(t==2){
            cin >> x >> y >> z;
            a[x]=a[y]^a[z];
        }
        else if(t==3){
            cin >> x >> y >> z;
            a[x]=a[y]&a[z];
        }
        else{
            cin >> x >> v;
            if((a[x]&q[v]).count()%2) ans+='1';
            else ans+='0';
        }
    }
    cout << ans;
}


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

const int MxN = 1e5 + 5;
const int MxV = 7e3 + 5;

static int N, Q, miu[MxV];
static bitset<MxV> val[MxN], mk1[MxV], mk2[MxV];

inline int getMiu(int x)
{
    int ans = 1;
    for (int i = 2; i * i <= x; i++)
        if (x % i == 0)
        {
             if ((x /= i) % i == 0)
                return 0;
            ans *= -1;
        }
    if (x != 1)
        ans *= -1;
    return ans;
}

inline void getMask1(int x, bitset<MxV> &ans)
{
    ans = 0;
    for (int i = 1; i * i <= x; i++)
        if (x % i == 0)
            ans[i] = ans[x / i] = 1;
}

inline void getMask2(int x, bitset<MxV> &ans)
{
    ans = 0;
    for (int i = 1; i < MxV / x; i++)
        if (miu[i])
            ans[x * i] = 1;
}

int main()
{
    for (int i = 1; i < MxV; i++)
    {
        miu[i] = getMiu(i);
        getMask1(i, mk1[i]);
        getMask2(i, mk2[i]);
    }
    scanf("%d%d", &N, &Q);
    while (Q--)
    {
        int op, x, y, z;
        scanf("%d%d%d", &op, &x, &y);
        if (op == 1)
            val[x] = mk1[y];
        else if (op == 4)
            putchar((val[x] & mk2[y]).count() & 1 ? '1' : '0');
        else
        {
            scanf("%d", &z);
            if (op == 2)
                val[x] = val[y] ^ val[z];
            else
                val[x] = val[y] & val[z];
        }
    }
    puts("");
    return 0;
}


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

const int MxN = 1e5 + 5;
const int MxV = 7e3 + 5;

static int N, Q, miu[MxV];
static bitset<MxV> val[MxN], mk1[MxV], mk2[MxV];

inline int getMiu(int x)
{
    for (int i = 2; i * i <= x; i++)
        if (x % (i * i) == 0)
            return 0;
    return 1;
}

inline void getMask1(int x, bitset<MxV> &ans)
{
    for (int i = 1; i * i <= x; i++)
        if (x % i == 0)
            ans[i] = ans[x / i] = 1;
}

inline void getMask2(int x, bitset<MxV> &ans)
{
    for (int i = x; i < MxV; i += x)
        if (miu[i / x])
            ans[i] = 1;
}

int main()
{
    for (int i = 1; i < MxV; i++)
    {
        miu[i] = getMiu(i);
        getMask1(i, mk1[i]);
    }
    for (int i = 1; i < MxV; i++)
        getMask2(i, mk2[i]);
    scanf("%d%d", &N, &Q);
    while (Q--)
    {
        int op, x, y, z;
        scanf("%d%d%d", &op, &x, &y);
        if (op == 1)
            val[x] = mk1[y];
        else if (op == 4)
            putchar('0' + ((val[x] & mk2[y]).count() & 1));
        else
        {
            scanf("%d", &z);
            if (op == 2)
                val[x] = val[y] ^ val[z];
            else
                val[x] = val[y] & val[z];
        }
    }
    puts("");
    return 0;
}


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

const int MxN = 1e5 + 5;
const int MxV = 7e3 + 5;

static int N, Q, miu[MxV];
static bitset<MxV> val[MxN], mk1[MxV], mk2[MxV];

inline int getMiu(int x)
{
    for (int i = 2; i * i <= x; i++)
        if (x % (i * i) == 0)
            return 0;
    return 1;
}

inline void getMask1(int x, bitset<MxV> &ans)
{
    for (int i = 1; i * i <= x; i++)
        if (x % i == 0)
            ans[i] = ans[x / i] = 1;
}

inline void getMask2(int x, bitset<MxV> &ans)
{
    for (int i = 1; i < MxV / x; i++)
        if (miu[i])
            ans[x * i] = 1;
}

int main()
{
    for (int i = 1; i < MxV; i++)
    {
        miu[i] = getMiu(i);
        getMask1(i, mk1[i]);
    }
    for (int i = 1; i < MxV; i++)
        getMask2(i, mk2[i]);
    scanf("%d%d", &N, &Q);
    while (Q--)
    {
        int op, x, y, z;
        scanf("%d%d%d", &op, &x, &y);
        if (op == 1)
            val[x] = mk1[y];
        else if (op == 4)
            putchar('0' + ((val[x] & mk2[y]).count() & 1));
        else
        {
            scanf("%d", &z);
            if (op == 2)
                val[x] = val[y] ^ val[z];
            else
                val[x] = val[y] & val[z];
        }
    }
    puts("");
    return 0;
}


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

const int MxN = 1e5 + 5;
const int MxV = 7e3 + 5;

static int N, Q, miu[MxV];
static bitset<MxV> val[MxN], mk1[MxV], mk2[MxV];

inline int getMiu(int x)
{
    int ans = 1;
    for (int i = 2; i * i <= x; i++)
        if (x % i == 0)
        {
             if ((x /= i) % i == 0)
                return 0;
            ans *= -1;
        }
    if (x != 1)
        ans *= -1;
    return ans;
}

inline void getMask1(int x, bitset<MxV> &ans)
{
    ans = 0;
    for (int i = 1; i * i <= x; i++)
        if (x % i == 0)
            ans[i] = ans[x / i] = 1;
}

inline void getMask2(int x, bitset<MxV> &ans)
{
    ans = 0;
    for (int i = 1; i < MxV / x; i++)
        if (miu[i])
            ans[x * i] = 1;
}

int main()
{
    for (int i = 1; i < MxV; i++)
    {
        miu[i] = getMiu(i);
        getMask1(i, mk1[i]);
    }
    for (int i = 1; i < MxV; i++)
        getMask2(i, mk2[i]);
    scanf("%d%d", &N, &Q);
    while (Q--)
    {
        int op, x, y, z;
        scanf("%d%d%d", &op, &x, &y);
        if (op == 1)
            val[x] = mk1[y];
        else if (op == 4)
            putchar('0' + ((val[x] & mk2[y]).count() & 1));
        else
        {
            scanf("%d", &z);
            if (op == 2)
                val[x] = val[y] ^ val[z];
            else
                val[x] = val[y] & val[z];
        }
    }
    puts("");
    return 0;
}


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

const int MxN = 1e5 + 5;
const int MxV = 7e3 + 5;

static int N, Q, miu[MxV];
static bitset<MxV> val[MxN], mk1[MxV], mk2[MxV];

inline int getMiu(int x)
{
    int ans = 1;
    for (int i = 2; i * i <= x; i++)
        if (x % i == 0)
        {
             if ((x /= i) % i == 0)
                return 0;
            ans *= -1;
        }
    if (x != 1)
        ans *= -1;
    return ans;
}

inline void getMask1(int x, bitset<MxV> &ans)
{
    ans = 0;
    for (int i = 1; i * i <= x; i++)
        if (x % i == 0)
            ans[i] = ans[x / i] = 1;
}

inline void getMask2(int x, bitset<MxV> &ans)
{
    ans = 0;
    for (int i = 1; i < MxV / x; i++)
        if (miu[i])
            ans[x * i] = 1;
}

int main()
{
    for (int i = 1; i < MxV; i++)
    {
        miu[i] = getMiu(i);
        getMask1(i, mk1[i]);
    }
    for (int i = 1; i < MxV; i++)
        getMask2(i, mk2[i]);
    scanf("%d%d", &N, &Q);
    while (Q--)
    {
        int op, x, y, z;
        scanf("%d%d%d", &op, &x, &y);
        if (op == 1)
            val[x] = mk1[y];
        else if (op == 4)
            putchar((val[x] & mk2[y]).count() & 1 ? '1' : '0');
        else
        {
            scanf("%d", &z);
            if (op == 2)
                val[x] = val[y] ^ val[z];
            else
                val[x] = val[y] & val[z];
        }
    }
    puts("");
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <bitset>
#include <cstring>
using namespace std;
const int maxn = 100001;
bitset<7010> a[maxn],b,c;
int re1[maxn], re2[maxn];
int cnt1, cnt2;
int re[7001][1000], cnt[7001], now[7001];
void get(int n){
	int e = (int) sqrt(n);
	for(int i = 1; i <= e; i++) {
		if(n % i == 0){
			re[n][++cnt[n]] = i;
			if(i * i != n && i != 1)
				re[n][++cnt[n]] = n / i;
		}
	}
}
void init(void) {
	for(int i = 1;i <=7000; i++) {
		get(i);
	}
}
void solve(int x, int y, int z) {
	b = a[x], c = a[y];
	a[z].reset();
	memset(now, 0, sizeof(now));
	for(int i = 7000; i >= 1; i--) {
		cnt1 = cnt2 = 0;
		for(int j = i; j <= 7000; j +=i) {
			if(b[j] & 1) cnt1++;
			if(c[j] & 1) cnt2++;
		}
		now[i] += cnt1 * cnt2;
		if(now[i]>0) {
			for(int j = 1; j <= cnt[i]; j++)
				now[re[i][j]] -= now[i];
		}

		a[z][i] = (now[i] & 1);
	}
	return;
}
int main() {
	int n, m, op, x, y, z, v;
	init();
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; i++) {
		scanf("%d", &op);
		if(op == 1) {
			scanf("%d%d", &x, &v);
			//printf("%d ", a[x][v] & 1);
			a[x][v] = a[x][v] ^ 1;
			//printf("%d\n", a[x][v] & 1);
		}else if(op == 2) {
			scanf("%d%d%d", &x, &y, &z);
			a[x] = a[y] ^ a[z];
		}else if(op == 3) {
			scanf("%d%d%d", &y, &z, &x);
			solve(x, y, z);
		}else if(op == 4) {
			scanf("%d%d", &x, &v);
			printf("%d\n", a[x][v] & 1);
		}
	}
}


#include <cstdio>
#include <algorithm>
#include <bitset>
#include <cstring>
#include <cmath>
using namespace std;
const int maxn = 100001;
bitset<7010> a[maxn],b,c;
int re1[maxn], re2[maxn];
int cnt1, cnt2;
int re[7001][1000], cnt[7001], now[7001];
void get_num(int n){
	int e = (int) sqrt(n);
	for(int i = 1; i <= e; i++) {
		if(n % i == 0){
			re[n][++cnt[n]] = i;
			if(i * i != n && i != 1)
				re[n][++cnt[n]] = n / i;
		}
	}
}
void init(void) {
	for(int i = 1;i <=7000; i++) {
		get_num(i);
	}
}
void solve(int x, int y, int z) {
	b = a[x], c = a[y];
	a[z].reset();
	memset(now, 0, sizeof(now));
	for(int i = 7000; i >= 1; i--) {
		cnt1 = cnt2 = 0;
		for(int j = i; j <= 7000; j +=i) {
			if(b[j] & 1) cnt1++;
			if(c[j] & 1) cnt2++;
		}
		now[i] += cnt1 * cnt2;
		if(now[i]>0) {
			for(int j = 1; j <= cnt[i]; j++)
				now[re[i][j]] -= now[i];
		}

		a[z][i] = (now[i] & 1);
	}
	return;
}
int main() {
	int n, m, op, x, y, z, v;
	init();
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; i++) {
		scanf("%d", &op);
		if(op == 1) {
			scanf("%d%d", &x, &v);
			//printf("%d ", a[x][v] & 1);
			a[x][v] = a[x][v] ^ 1;
			//printf("%d\n", a[x][v] & 1);
		}else if(op == 2) {
			scanf("%d%d%d", &x, &y, &z);
			a[x] = a[y] ^ a[z];
		}else if(op == 3) {
			scanf("%d%d%d", &z, &x, &y);
			solve(x, y, z);
		}else if(op == 4) {
			scanf("%d%d", &x, &v);
			printf("%d", a[x][v] & 1);
		}
	}
}


#include <cstdio>
#include <algorithm>
#include <bitset>
#include <cstring>
#include <cmath>
using namespace std;
const int maxn = 100001;
bitset<7010> a[maxn],b,c;
int re1[maxn], re2[maxn];
int cnt1, cnt2;
int re[7001][1000], cnt[7001], now[7001];
void get_num(int n){
	int e = (int) sqrt(n);
	for(int i = 1; i <= e; i++) {
		if(n % i == 0){
			re[n][++cnt[n]] = i;
			if(i * i != n && i != 1)
				re[n][++cnt[n]] = n / i;
		}
	}
}
void init(void) {
	for(int i = 1;i <=7000; i++) {
		get_num(i);
	}
}
void solve(int x, int y, int z) {
	b = a[x], c = a[y];
	a[z].reset();
	memset(now, 0, sizeof(now));
	for(int i = 7000; i >= 1; i--) {
		cnt1 = cnt2 = 0;
		for(int j = i; j <= 7000; j +=i) {
			if(b[j] & 1) cnt1++;
			if(c[j] & 1) cnt2++;
		}
		now[i] += cnt1 * cnt2;
		if(now[i]>0) {
			for(int j = 1; j <= cnt[i]; j++)
				now[re[i][j]] -= now[i];
		}

		a[z][i] = (now[i] & 1);
	}
	return;
}
int main() {
	int n, m, op, x, y, z, v;
	init();
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; i++) {
		scanf("%d", &op);
		if(op == 1) {
			scanf("%d%d", &x, &v);
			//printf("%d ", a[x][v] & 1);
			a[x][v] = a[x][v] ^ 1;
			//printf("%d\n", a[x][v] & 1);
		}else if(op == 2) {
			scanf("%d%d%d", &x, &y, &z);
			a[x] = a[y] ^ a[z];
		}else if(op == 3) {
			scanf("%d%d%d", &y, &z, &x);
			solve(x, y, z);
		}else if(op == 4) {
			scanf("%d%d", &x, &v);
			printf("%d\n", a[x][v] & 1);
		}
	}
}


#include <cstdio>
#include <algorithm>
#include <bitset>
#include <cstring>
#include <cmath>
using namespace std;
const int maxn = 100001;
bitset<7010> a[maxn],b,c;
int re1[maxn], re2[maxn];
int cnt1, cnt2;
int re[7001][1000], cnt[7001], now[7001];
void get_num(int n){
	int e = (int) sqrt(n);
	for(int i = 1; i <= e; i++) {
		if(n % i == 0){
			re[n][++cnt[n]] = i;
			if(i * i != n && i != 1)
				re[n][++cnt[n]] = n / i;
		}
	}
}
void init(void) {
	for(int i = 1;i <=7000; i++) {
		get_num(i);
	}
}
void solve(int x, int y, int z) {
	b = a[x], c = a[y];
	a[z].reset();
	memset(now, 0, sizeof(now));
	for(int i = 7000; i >= 1; i--) {
		cnt1 = cnt2 = 0;
		for(int j = i; j <= 7000; j +=i) {
			if(b[j] & 1) cnt1++;
			if(c[j] & 1) cnt2++;
		}
		now[i] += cnt1 * cnt2;
		if(now[i]>0) {
			for(int j = 1; j <= cnt[i]; j++)
				now[re[i][j]] -= now[i];
		}

		a[z][i] = (now[i] & 1);
	}
	return;
}
int main() {
	int n, m, op, x, y, z, v;
	init();
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; i++) {
		scanf("%d", &op);
		if(op == 1) {
			scanf("%d%d", &x, &v);
			//printf("%d ", a[x][v] & 1);
			a[x][v] = a[x][v] ^ 1;
			//printf("%d\n", a[x][v] & 1);
		}else if(op == 2) {
			scanf("%d%d%d", &x, &y, &z);
			a[x] = a[y] ^ a[z];
		}else if(op == 3) {
			scanf("%d%d%d", &y, &z, &x);
			solve(x, y, z);
		}else if(op == 4) {
			scanf("%d%d", &x, &v);
			printf("%d", a[x][v] & 1);
		}
	}
}


#include <cstdio>
#include <algorithm>
#include <bitset>
#include <cstring>
#include <cmath>
using namespace std;
const int maxn = 100001;
bitset<7010> a[maxn],b,c;
int re1[maxn], re2[maxn];
int cnt1, cnt2;
int re[7001][1000], cnt[7001], now[7001];
void get_num(int n){
	int e = (int) sqrt(n);
	for(int i = 1; i <= e; i++) {
		if(n % i == 0){
			re[n][++cnt[n]] = i;
			if(i * i != n && i != 1)
				re[n][++cnt[n]] = n / i;
		}
	}
}
void init(void) {
	for(int i = 1;i <=7000; i++) {
		get_num(i);
	}
}
void solve(int x, int y, int z) {
	b = a[x], c = a[y];
	a[z].reset();
	memset(now, 0, sizeof(now));
	for(int i = 7000; i >= 1; i--) {
		cnt1 = cnt2 = 0;
		for(int j = i; j <= 7000; j +=i) {
			if(b[j] & 1) cnt1++;
			if(c[j] & 1) cnt2++;
		}
		now[i] += cnt1 * cnt2;
		for(int j = 1; j <= cnt[i]; j++)
			now[re[i][j]] -= now[i];
		a[z][i] = (now[i] & 1);
	}
	return;
}
int main() {
	int n, m, op, x, y, z, v;
	init();
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; i++) {
		scanf("%d", &op);
		if(op == 1) {
			scanf("%d%d", &x, &v);
			a[x].reset();
			a[x][v] = 1;
		}else if(op == 2) {
			scanf("%d%d%d", &x, &y, &z);
			a[x] = a[y] ^ a[z];
		}else if(op == 3) {
			scanf("%d%d%d", &z, &x, &y);
			solve(x, y, z);
		}else if(op == 4) {
			scanf("%d%d", &x, &v);
			printf("%d", a[x][v] & 1);
		}
	}
}


#include <cstdio>
#include <algorithm>
#include <bitset>
#include <cstring>
#include <cmath>
using namespace std;
const int maxn = 100001;
bitset<7010> a[maxn],b,c;
int re1[maxn], re2[maxn];
int cnt1, cnt2;
int re[7001][1000], cnt[7001], now[7001];
void get_num(int n){
	int e = (int) sqrt(n);
	for(int i = 1; i <= e; i++) {
		if(n % i == 0){
			re[n][++cnt[n]] = i;
			if(i * i != n && i != 1)
				re[n][++cnt[n]] = n / i;
		}
	}
}
void init(void) {
	for(int i = 1;i <=7000; i++) {
		get_num(i);
	}
}
void solve(int x, int y, int z) {
	b = a[x], c = a[y];
	a[z].reset();
	memset(now, 0, sizeof(now));
	for(int i = 7000; i >= 1; i--) {
		cnt1 = cnt2 = 0;
		for(int j = i; j <= 7000; j +=i) {
			if(b[j] & 1) cnt1++;
			if(c[j] & 1) cnt2++;
		}
		now[i] += cnt1 * cnt2;
		if(now[i]>0) {
			for(int j = 1; j <= cnt[i]; j++)
				now[re[i][j]] -= now[i];
		}

		a[z][i] = (now[i] & 1);
	}
	return;
}
int main() {
	int n, m, op, x, y, z, v;
	init();
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; i++) {
		scanf("%d", &op);
		if(op == 1) {
			scanf("%d%d", &x, &v);
//			a[x][v] = a[x][v] ^ 1;
			a[x].reset();
			a[x][v] = 1;
		}else if(op == 2) {
			scanf("%d%d%d", &x, &y, &z);
			a[x] = a[y] ^ a[z];
		}else if(op == 3) {
			scanf("%d%d%d", &z, &x, &y);
			solve(x, y, z);
		}else if(op == 4) {
			scanf("%d%d", &x, &v);
			printf("%d", a[x][v] & 1);
		}
	}
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define de(x) cout<<#x<<" = "<<x<<"\n"
#define dd(x) cout<<#x<<" = "<<x<<" "
#define mes(p) memset(p,0,sizeof(p))
#define per(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(x) x.begin(),x.end()
#define rson mid+1,r,rt<<1|1
#define sz(x) (int)x.size()
#define lson l,mid,rt<<1
#define pb push_back
#define mp make_pair
//#define ls (rt<<1)
#define se second
//#define rs (ls|1)
#define fi first
typedef pair <int ,int > pi;
typedef vector <int > vi;
typedef long long ll;
const int maxn  = 1e5+5;
const int mod = 1e9+7;
const int N = 7000;
int mu[N+1], n, q, t, x, y, z;
bitset <N+5> f[N+1], a[N+1], b[maxn];
int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
	cin >> n >> q;
	rep(i,1,N+1) mu[i] = 1;
	rep(i,2,N+1) for(int j=i*i;j<=N;j+=i*i) mu[j] = 0;
	rep(i,1,N+1)
	for(int j=i;j<=N;j+=i) a[j][i] = 1, f[i][j] = mu[j/i];
	while(q--){
		cin >> t>> x>> y;
		if(t==1) b[x] = a[y];
		else {
			if(t!=4)cin>> z;
			if(t==2) b[x] = b[y]^b[z];
			else if(t==3) b[x] = b[y]&b[z];
			else  cout << ((b[x]&f[y]).count()&1);
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define de(x) cout<<#x<<" = "<<x<<"\n"
#define dd(x) cout<<#x<<" = "<<x<<" "
#define mes(p) memset(p,0,sizeof(p))
#define per(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(x) x.begin(),x.end()
#define rson mid+1,r,rt<<1|1
#define sz(x) (int)x.size()
#define lson l,mid,rt<<1
#define pb push_back
#define mp make_pair
//#define ls (rt<<1)
#define se second
//#define rs (ls|1)
#define fi first
typedef pair <int ,int > pi;
typedef vector <int > vi;
typedef long long ll;
const int maxn  = 1e6+5;
const int mod = 1e9+7;
const int N = 7000;
int mu[maxn], n, q, t, x, y, z;
bitset <N+5> f[N+1], a[N+1], b[maxn];
int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
	cin >> n >> q;
	rep(i,1,N+1) mu[i] = 1;
	rep(i,2,N+1) for(int j=i*i;j<=N;j+=i*i) mu[j] = 0;
	rep(i,1,N+1)
	for(int j=i;j<=N;j+=i) a[j][i] = 1, f[j][i] = mu[j/i];
	while(q--){
		cin >> t>> x>> y;
		if(t==1) b[x] = a[y];
		else {
			if(t!=4)cin>> z;
			if(t==2) b[x] = b[y]^b[z];
			else if(t==3) b[x] = b[y]&b[z];
			else  cout << ((b[x]&f[y]).count()&1);
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define de(x) cout<<#x<<" = "<<x<<"\n"
#define dd(x) cout<<#x<<" = "<<x<<" "
#define mes(p) memset(p,0,sizeof(p))
#define per(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(x) x.begin(),x.end()
#define rson mid+1,r,rt<<1|1
#define sz(x) (int)x.size()
#define lson l,mid,rt<<1
#define pb push_back
#define mp make_pair
//#define ls (rt<<1)
#define se second
//#define rs (ls|1)
#define fi first
typedef pair <int ,int > pi;
typedef vector <int > vi;
typedef long long ll;
const int maxn  = 1e5+5;
const int mod = 1e9+7;
const int N = 7000;
int mu[N+1], n, q, t, x, y, z;
bitset <N+5> f[N+1], a[N+1], b[maxn];
int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
	cin >> n >> q;
	rep(i,1,N+1) mu[i] = 1;
	rep(i,2,N+1) for(int j=i*i;j<=N;j+=i*i) mu[j] = 0;
	rep(i,1,N+1)
	for(int j=i;j<=N;j+=i) a[j][i] = 1, f[j][i] = mu[j/i];
	while(q--){
		cin >> t>> x>> y;
		if(t==1) b[x] = a[y];
		else {
			if(t!=4)cin>> z;
			if(t==2) b[x] = b[y]^b[z];
			else if(t==3) b[x] = b[y]&b[z];
			else  cout << ((b[x]&f[y]).count()&1);
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int maxn = 1e5 + 1;
const ll MOD = 1e9 + 7;
const int SZ = 7001;
bitset<SZ> sets[maxn];
bitset<SZ> del_by[SZ];
bitset<SZ> four[SZ];
bool square_free[SZ];

int main() {
#ifdef __kolya
    freopen("../input.txt", "r", stdin);
#else
#endif
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    int n, q;
    cin >> n >> q;
    for (int v = 1; v < SZ; ++v) {
        square_free[v] = 1;
        int x = v;
        for (int i = 2; i <= x; ++i) {
            if (x % i == 0) {
                int cnt = 0;
                while (x % i == 0) {
                    ++cnt;
                    x /= i;
                }
                if (cnt >= 2) {
                    square_free[v] = 0;
                    break;
                }
            }
        }

    }

    for (int v = 1; v < SZ; ++v) {
        for (int i = 1; i <= v; ++i) {
            if (v % i == 0) {
                del_by[v].set(i);
            }

        }
        for (int i = 1; i * v < SZ; ++i) {
            if (square_free[i]) {
                four[v].set(i * v);
            }
        }
    }

    for (int i = 1; i <= q; ++i) {
        int tp;
        cin >> tp;
        if (tp == 1) {
            int x;
            cin >> x;
            int v;
            cin >> v;
//            cout << 1 << "\n";
//            print(del_by[v]);
            sets[x] = del_by[v];
        } else if (tp == 2) {
            int x, y, z;
            cin >> x >> y >> z;
            sets[x] = sets[y] ^ sets[z];
//            cout << 2 << "\n";
//            print(sets[y]);
//            print(sets[z]);
//            print(sets[x]);
        } else if (tp == 3) {
            int x, y, z;
            cin >> x >> y >> z;
            sets[x] = sets[y] & sets[z];
//            cout << 3 << "\n";
//            print(sets[y]);
//            print(sets[z]);
//            print(sets[x]);
        } else{
            int x, v;
            cin >> x >> v;
//            cout << 4 << "\n";
            auto res = sets[x] & four[v];
//            print(sets[x]);
//            print(four[v]);
//            print(res);

            cout << (res.count() & 1);
        }
    }
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
#define R register
#define int long long
#define ld double
#define debug printf("zjy\n")
#define poi(x,y) (((x-1)*m+y)*4)
inline int read(){
	int a=0,b=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')b=-1;c=getchar();}
	while(isdigit(c)){a=a*10+c-'0';c=getchar();}
	return a*b;
}
const int N=350;
int n,k,w[N][2],f[N][N*10],up,ans;
signed main(){
	n=read();k=read();
	for(R int i=1,a;i<=n;i++){
		a=read();
		while(a%2==0){
			a/=2;
			w[i][0]++;
		}
		while(a%5==0){
			a/=5;
			w[i][1]++;
		}
	}
	memset(f,0xcf,sizeof(f));
	f[0][0]=0;
	for(R int i=1;i<=n;i++){
		up+=w[i][1];
		for(R int j=min(i,k);j>=1;j--){
			for(R int l=up;l>=w[i][1];l--){
				f[j][l]=max(f[j][l],f[j-1][l-w[i][1]]+w[i][0]);
				if(j==k)ans=max(ans,min(l,f[j][l]));
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}


#include<iostream>
#include<cstring>
#include<cmath>
#include<cstring>
#include<cstdio>
using namespace std;
int n,m,s2,s5,a,tmp,dp[200][200005];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		s2=0; s5=0;
		tmp=a;
		while(tmp%2)
		{
			tmp/=2;
			s2++;
		}
		tmp=a;
		while(tmp%5)
		{
			tmp/=5;
			s5++;
		}
		for(int j=m;j>=1;j--)
			for(int k=13130;k>=1;k--)

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db double
#define N 1000100
#define jd (isdigit(c))
#define gg c=getchar()
#define inf 233333333333333
#define eps 1e-7
#define mod 1000000007
#define ls k<<1
#define rs k<<1|1
#define root t[0].ch[1]
inline ll read()
{
    ll f=0;bool x=1;char gg;
    for(;!jd;gg)if(c=='-')x=0;
    for(;jd;gg)f=(f<<1)+(f<<3)+(c&15);
    return x?f:-f;
}
inline void write(ll x)
{
    if(!x)putchar('0');
    else
    {
        if(x<0)putchar('-'),x=-x;
        char s[25];
        int j=0;
        for(;x;x/=10)s[j++]=x%10;
        for(int i=j-1;~i;i--)putchar(s[i]+48);
    }
    putchar('\n');
}
ll n,k,a[N],b[N],dp[205][15005],ans;
int main()
{
	n=read(),k=read();
	memset(dp,-1,sizeof dp);
	dp[0][0]=0;
	for(int i=1;i<=n;i++)
	{
		ll p=read();
		while(!(p%2))a[i]++,p/=2;
		while(!(p%5))b[i]++,p/=5;
	}
	for(int i=1;i<=n;i++)
		for(int j=k;j;j--)
			for(int l=15000;l>=a[i];l--)
				if(~dp[j-1][l-a[i]])dp[j][l]=max(dp[j][l],dp[j-1][l-a[i]]+b[i]);
	for(int i=0;i<=15000;i++)ans=max(ans,min((ll)i,dp[k][i]));
	write(ans);
	return 0;
}


#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define QWQ cout<<"QwQ"<<endl;
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
const int N=101010;
const int qwq=303030;
const int inf=0x3f3f3f3f;
int n,m;
int big;
int a[1234];
int f[234][15050];

int main() {
	memset(f,-0x3f,sizeof(f)); f[0][0] = 0;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		int wu = 0, er = 0;
		while(a[i]%5==0) wu++, a[i] /= 5;
		while(a[i]%2==0) er++, a[i] /= 2;
		big += wu;
		for(int j=min(i,m);j>=1;j--)
		for(int k=big;k>=wu;k--)
		f[j][k] = max(f[j][k],f[j-1][k-wu] + er);
	}
	int ans = 0;
	for(int i=0;i<=big;i++) ans = max(ans,min(i,f[m][i]));
	cout<<ans;
	return 0;
}


#pragma GCC optimize(2)
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define ll long long
ll f[205][6000];
ll a[205],b[205];//a[]=因子2的个数，b[]=因子5的个数
int n,m;//n个东西,取m个
ll ans;
int main()
{
	//cout<<log(1e18)/log(5)*200<<endl;//测试X最大值，即5的最多个数。
	/*
	ios::sync_with_stdio(false);
    cin.tie(0);
	memset(f,-1,sizeof(f));
	f[0][0]=0;
	cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        ll x;cin>>x;
		while(x%2==0) x/=2, a[i]++;
        while(x%5==0) x/=5, b[i]++;
    }
    */
    ios::sync_with_stdio(false);
    cin.tie(0);

    memset(f,-1,sizeof(f));
    f[0][0]=0;

    cin>>n>>m;

    for(int i=1;i<=n;i++){
        ll t;
        cin>>t;
        while(t%2==0)t/=2,a[i]++;
        while(t%5==0)t/=5,b[i]++;
    }
    for(int i=1;i<=n;i++)
    {
		for(int j=m;j>=1;j--)
    	{
    		for(int k=6000;k>=b[i];k--)
    		{
    			if(f[j-1][k-b[i]]!=-1)
    				f[j][k]=max(f[j][k],f[j-1][k-b[i]]+a[i]);
			}
    	}
	}
	for(ll k=1;k<=6000;k++)
		ans=max(ans,min(k,f[m][k]));
	cout<<ans;
	return 0;
}
//dp[j][k]表示拿了j个数，共有k个因子5的情况下因子2的最大数量量


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#define int long long

using namespace std;

inline int read() {
    char c = getchar(); int x = 0, f = 1;
    for (; c > '9' || c < '0'; c = getchar()) if (c == '-') f = -1;
    for (; c >='0' && c <='9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
    return x * f;
}

int a[1000], b[1000];
int dp[1000][10000];

void djj_lxy () {
    int n = read(), m = read(), x, ans = 0;
    for (register int i = 1; i <= n; i ++) {
        x = read();
        for (; x % 2 == 0; )
            x /= 2, a[i] ++;
        for (; x % 5 == 0; )
            x /= 5, b[i] ++;
    }
    memset (dp, -1, sizeof dp);
    dp[0][0] = 0;
    for (register int i = 1; i <= n; i ++)
        for (register int j = m; j >= 0; j --)
            for (register int k = 10000; k >= 0; k --)
                if (j >= 1 && k >= b[i] && dp[j - 1][k - b[i]] != -1)
                    dp[j][k] = max (dp[j][k], dp[j - 1][k - b[i]] + a[i]);
    for (register int i = 0; i <= 10000; i ++)
        ans = max (ans, min (i, dp[m][i]));
    printf ("%lld\n", ans);
}

signed main () {
    djj_lxy ();
}


#include <iostream>
#include <cstring>

using namespace std;

long long n,k;
long long s;
long long a[201];
long long s2[201],s5[201];
long long x;
long long dp[201][20001];

signed main(){
	cin>>n>>k;
	for(long long i = 1;i <= n;i++){
		cin>>a[i];
		x = a[i];
		while(x % 2 == 0){
			s2[i]++,x /= 2;
		}
        while(x % 5 == 0){
			s5[i]++,x /= 5;
		}
	}
	memset(dp,-1,sizeof(dp));
	dp[0][0] = 0;

	for(long long i = 1;i <= n;i++){
        for(long long j = k;j >= 1;j--){
            for(long long k = 10000;k >= s5[i];k--){
                dp[j][k] = max(dp[j][k],dp[j-1][k-s5[i]]+s2[i]);
			}
		}
    }

    for(long long i = 0;i <= 10000;i++)s = max(s,min(i,dp[k][i]));

	cout<<s<<endl;

	return 0;
}


#include<iostream>
#include<cstdio>
#include<queue>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
ll a[210],b[210],x,dp[210][6500],n,m,ans;

int main(){
	cin>>n>>m;ans=0;
	for(int i=1;i<=n;i++) {
		scanf("%lld",&x);
		while(x%2==0){x/=2;a[i]++;}
		while(x%5==0){x/=5;b[i]++;}
	}
	memset(dp,-1,sizeof(dp));
	dp[0][0]=0;
	for(int i=1;i<=n;i++){
		for(int j=m;j>=1;j--){
			for(int k=6500;k>=b[i];k--){
				dp[j][k]=max(dp[j][k],dp[j-1][k-b[i]]+a[i]);
			}
		}
	}
	for(ll i=1;i<=6500;i++){
		ans=max(ans,min((i),dp[m][i]));
	}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;
#define gc getchar()
#define lowbit(x) (x&(-x))
#define int long long
const unsigned long long p1=19260817,p2=1e9+7,B=211;
template<class T>
inline bool read(T& x){
	x=0;
	bool f=0;
	char ch;
	for(ch=gc;!isdigit(ch);ch=gc){
		if(ch==EOF)return 0;
		f|=ch=='-';
	}
	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48),ch=gc;
	if(f)x=-x;
	return 1;
}
template<class T>
void write(T x){
    if(x<0){putchar('-'),write(-x);return;}
	if(x>9)write(x/10);
	putchar((x%10)|48);
}
template<class T>
inline void writeln(T x){
	write(x),putchar('\n');
}
template<class T>
inline void writespace(T x){
	write(x),putchar(' ');
}

int n,k,ans;
int f[210][15010],num[210],sum;

void pack(int a,int b){
	sum+=a;
	for(register int i=k;i>=1;--i){
		for(register int j=sum;j>=a;--j){
			f[i][j]=max(f[i][j],f[i-1][j-a]+b);
			ans=max(ans,min(f[i][j],j));
		}
	}
}

signed main(){
	srand(20050210);
	read(n);read(k);
	memset(f,-1,sizeof(f));f[0][0]=0;
	for(register int i=1;i<=n;++i){
		read(num[i]);
		int five=0,two=0;
		while(num[i]%2==0)++two,num[i]/=2;
		while(num[i]%5==0)++five,num[i]/=5;
		pack(five,two);
	}

	write(ans);
	return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;
#define gc getchar()
#define lowbit(x) (x&(-x))
//#define int long long
const unsigned long long p1=19260817,p2=1e9+7,B=211;
template<class T>
inline bool read(T& x){
	x=0;
	bool f=0;
	char ch;
	for(ch=gc;!isdigit(ch);ch=gc){
		if(ch==EOF)return 0;
		f|=ch=='-';
	}
	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48),ch=gc;
	if(f)x=-x;
	return 1;
}
template<class T>
void write(T x){
    if(x<0){putchar('-'),write(-x);return;}
	if(x>9)write(x/10);
	putchar((x%10)|48);
}
template<class T>
inline void writeln(T x){
	write(x),putchar('\n');
}
template<class T>
inline void writespace(T x){
	write(x),putchar(' ');
}

int n,k,ans;
int f[210][4000],num[210],sum;

void pack(int a,int b){
	sum+=a;
	for(register int i=k;i>=1;--i){
		for(register int j=sum;j>=a;--j){
			f[i][j]=max(f[i][j],f[i-1][j-a]+b);
			ans=max(ans,min(f[i][j],j));
		}
	}
}

signed main(){
	srand(20050210);
	read(n);read(k);
	for(register int i=1;i<=n;++i){
		read(num[i]);
		int five=0,two=0;
		while(num[i]%2==0)++two,num[i]/=2;
		while(num[i]%5==0)++five,num[i]/=5;
		pack(five,two);
	}

	write(ans);
	return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;
#define gc getchar()
#define lowbit(x) (x&(-x))
//#define int long long
const unsigned long long p1=19260817,p2=1e9+7,B=211;
template<class T>
inline bool read(T& x){
	x=0;
	bool f=0;
	char ch;
	for(ch=gc;!isdigit(ch);ch=gc){
		if(ch==EOF)return 0;
		f|=ch=='-';
	}
	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48),ch=gc;
	if(f)x=-x;
	return 1;
}
template<class T>
void write(T x){
    if(x<0){putchar('-'),write(-x);return;}
	if(x>9)write(x/10);
	putchar((x%10)|48);
}
template<class T>
inline void writeln(T x){
	write(x),putchar('\n');
}
template<class T>
inline void writespace(T x){
	write(x),putchar(' ');
}

int n,k,ans;
int f[210][100010],num[210],sum;

void pack(int a,int b){
	sum+=a;
	for(register int i=k;i>=1;--i){
		for(register int j=sum;j>=a;--j){
			f[i][j]=max(f[i][j],f[i-1][j-a]+b);
			ans=max(ans,min(f[i][j],j));
		}
	}
}

signed main(){
	srand(20050210);
	read(n);read(k);
	for(register int i=1;i<=n;++i){
		read(num[i]);
		int five=0,two=0;
		while(num[i]%2==0)++two,num[i]/=2;
		while(num[i]%5==0)++five,num[i]/=5;
		pack(five,two);
	}

	write(ans);
	return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;
#define gc getchar()
#define lowbit(x) (x&(-x))
#define int long long
const unsigned long long p1=19260817,p2=1e9+7,B=211;
template<class T>
inline bool read(T& x){
	x=0;
	bool f=0;
	char ch;
	for(ch=gc;!isdigit(ch);ch=gc){
		if(ch==EOF)return 0;
		f|=ch=='-';
	}
	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48),ch=gc;
	if(f)x=-x;
	return 1;
}
template<class T>
void write(T x){
    if(x<0){putchar('-'),write(-x);return;}
	if(x>9)write(x/10);
	putchar((x%10)|48);
}
template<class T>
inline void writeln(T x){
	write(x),putchar('\n');
}
template<class T>
inline void writespace(T x){
	write(x),putchar(' ');
}

int n,k,ans;
int f[210][15010],num[210],sum;

void pack(int a,int b){
	sum+=a;
	for(register int i=k;i>=1;--i){
		for(register int j=sum;j>=a;--j){
			f[i][j]=max(f[i][j],f[i-1][j-a]+b);
			//ans=max(ans,min(f[i][j],j));
		}
	}
}

signed main(){
	srand(20050210);
	read(n);read(k);
	memset(f,-1,sizeof(f));f[0][0]=0;
	for(register int i=1;i<=n;++i){
		read(num[i]);
		int five=0,two=0;
		while(num[i]%2==0)++two,num[i]/=2;
		while(num[i]%5==0)++five,num[i]/=5;
		pack(two,five);
	}
	for(register int i=0;i<=sum;++i)ans=max(ans,min(f[k][i],i));
	write(ans);
	return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;
#define gc getchar()
#define lowbit(x) (x&(-x))
//#define int long long
const unsigned long long p1=19260817,p2=1e9+7,B=211;
template<class T>
inline bool read(T& x){
	x=0;
	bool f=0;
	char ch;
	for(ch=gc;!isdigit(ch);ch=gc){
		if(ch==EOF)return 0;
		f|=ch=='-';
	}
	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48),ch=gc;
	if(f)x=-x;
	return 1;
}
template<class T>
void write(T x){
    if(x<0){putchar('-'),write(-x);return;}
	if(x>9)write(x/10);
	putchar((x%10)|48);
}
template<class T>
inline void writeln(T x){
	write(x),putchar('\n');
}
template<class T>
inline void writespace(T x){
	write(x),putchar(' ');
}

int n,k,ans;
int f[210][400],num[210],sum;

void pack(int a,int b){
	sum+=a;
	for(register int i=k;i>=1;--i){
		for(register int j=sum;j>=a;--j){
			f[i][j]=max(f[i][j],f[i-1][j-a]+b);
			ans=max(ans,min(f[i][j],j));
		}
	}
}

signed main(){
	srand(20050210);
	read(n);read(k);
	for(register int i=1;i<=n;++i){
		read(num[i]);
		int five=0,two=0;
		while(num[i]%2==0)++two,num[i]/=2;
		while(num[i]%5==0)++five,num[i]/=5;
		pack(five,two);
	}

	write(ans);
	return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;
#define gc getchar()
#define lowbit(x) (x&(-x))
#define int long long
const unsigned long long p1=19260817,p2=1e9+7,B=211;
template<class T>
inline bool read(T& x){
	x=0;
	bool f=0;
	char ch;
	for(ch=gc;!isdigit(ch);ch=gc){
		if(ch==EOF)return 0;
		f|=ch=='-';
	}
	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48),ch=gc;
	if(f)x=-x;
	return 1;
}
template<class T>
void write(T x){
    if(x<0){putchar('-'),write(-x);return;}
	if(x>9)write(x/10);
	putchar((x%10)|48);
}
template<class T>
inline void writeln(T x){
	write(x),putchar('\n');
}
template<class T>
inline void writespace(T x){
	write(x),putchar(' ');
}

int n,k,ans;
int f[210][15010],num[210],sum;

void pack(int a,int b){
	sum+=a;
	for(register int i=k;i>=1;--i){
		for(register int j=sum;j>=a;--j){
			f[i][j]=max(f[i][j],f[i-1][j-a]+b);
			ans=max(ans,min(f[i][j],j));
		}
	}
}

signed main(){
	srand(20050210);
	read(n);read(k);
	for(register int i=1;i<=n;++i){
		read(num[i]);
		int five=0,two=0;
		while(num[i]%2==0)++two,num[i]/=2;
		while(num[i]%5==0)++five,num[i]/=5;
		pack(five,two);
	}

	write(ans);
	return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;
#define gc getchar()
#define lowbit(x) (x&(-x))
#define int long long
const unsigned long long p1=19260817,p2=1e9+7,B=211;
template<class T>
inline bool read(T& x){
	x=0;
	bool f=0;
	char ch;
	for(ch=gc;!isdigit(ch);ch=gc){
		if(ch==EOF)return 0;
		f|=ch=='-';
	}
	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48),ch=gc;
	if(f)x=-x;
	return 1;
}
template<class T>
void write(T x){
    if(x<0){putchar('-'),write(-x);return;}
	if(x>9)write(x/10);
	putchar((x%10)|48);
}
template<class T>
inline void writeln(T x){
	write(x),putchar('\n');
}
template<class T>
inline void writespace(T x){
	write(x),putchar(' ');
}

int n,k,ans;
int f[210][15010],num[210],sum;

void pack(int a,int b){
	sum+=a;
	for(register int i=k;i>=1;--i){
		for(register int j=sum;j>=0;--j){
			f[i][j]=max(f[i][j],f[i-1][j-a]+b);
			ans=max(ans,min(f[i][j],j));
		}
	}
}

signed main(){
	srand(20050210);
	read(n);read(k);
	for(register int i=1;i<=n;++i){
		read(num[i]);
		int five=0,two=0;
		while(num[i]%2==0)++two,num[i]/=2;
		while(num[i]%5==0)++five,num[i]/=5;
		pack(five,two);
	}

	write(ans);
	return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;
#define gc getchar()
#define lowbit(x) (x&(-x))
#define int long long
const unsigned long long p1=19260817,p2=1e9+7,B=211;
template<class T>
inline bool read(T& x){
	x=0;
	bool f=0;
	char ch;
	for(ch=gc;!isdigit(ch);ch=gc){
		if(ch==EOF)return 0;
		f|=ch=='-';
	}
	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48),ch=gc;
	if(f)x=-x;
	return 1;
}
template<class T>
void write(T x){
    if(x<0){putchar('-'),write(-x);return;}
	if(x>9)write(x/10);
	putchar((x%10)|48);
}
template<class T>
inline void writeln(T x){
	write(x),putchar('\n');
}
template<class T>
inline void writespace(T x){
	write(x),putchar(' ');
}

int n,k,ans;
int f[210][15010],num[210],sum;

void pack(int a,int b){
	sum+=a;
	for(register int i=k;i>=1;--i){
		for(register int j=sum;j>=a;--j){
            if(f[i-1][j-a]>=0)
			f[i][j]=max(f[i][j],f[i-1][j-a]+b);
			//ans=max(ans,min(f[i][j],j));
		}
	}
}

signed main(){
	srand(20050210);
	read(n);read(k);
	memset(f,-1,sizeof(f));f[0][0]=0;
	for(register int i=1;i<=n;++i){
		read(num[i]);
		int five=0,two=0;
		while(num[i]%2==0)++two,num[i]/=2;
		while(num[i]%5==0)++five,num[i]/=5;
		pack(two,five);
	}
	for(register int i=0;i<=sum;++i)ans=max(ans,min(f[k][i],i));
	write(ans);
	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define pb push_back
#define rsz resize
#define ins insert
#define mp make_pair
#define beg(x) x.begin()
#define en(x) x.end()
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define lb lower_bound
#define ub upper_bound
#define umap unordered_map
#define uset unordered_set
#define pqueue priority_queue

//Some for loop stuff stolen from tmw's template
#define for_base(i, a, b, x) for (int i=((a)<(b))?(a):(a)-1; ((a)<(b))?i<(b):i>=(b); ((a)<(b))?i+=(x):i-=(x))
#define FOR1(a) for_base(i, 0, a, 1)
#define FOR2(i, a) for_base(i, 0, a, 1)
#define FOR3(i, a, b) for_base(i, a, b, 1)
#define FOR4(i, a, b, x) for_base(i, a, b, x)
#define FIFTH(a, b, c, d, e, ...) e
#define FOR(...) FIFTH(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define in(i, x) for (auto& i : x)
#define FIT(i, x) for (auto i=(x).begin(); i!=(x).end(); ++i)
#define RIT(i, x) for (auto i=(x).rbegin(); i!=(x).rend(); ++i)

using ll=long long;
using db=double;
using ld=long double;
using pii=pair<int, int>;
using pll=pair<ll, ll>;
using pdd=pair<db, db>;
using vi=vector<int>;
using vl=vector<ll>;
using vd=vector<db>;
using vs=vector<string>;
using vii=vector<pii>;
using vll=vector<pll>;
using vdd=vector<pdd>;
template<class T> using min_heap=pqueue<T, vector<T>, greater<T>>;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<class T> bool ckmin(T& a, const T& b) {return (b<a)?a=b, 1:0;}
template<class T> bool ckmax(T& a, const T& b) {return (a<b)?a=b, 1:0;}

//Read/write stuff also partially stolen from tmw
template<class T> void read(T& x) {
    cin >> x;
}
template<class H, class T> void read(pair<H, T>& p) {
    cin >> p.fi >> p.se;
}
template<class T> void read(vector<T>& v) {
    in(i, v)
        read(i);
}
template<class T> void read(T a[], int n) {
    FOR(n)
        read(a[i]);
}
template<class H, class... T> void read(H& h, T&... t) {
    read(h);
    read(t...);
}

template<class H, class T> ostream& operator<<(ostream& o, const pair<H, T> &p) {
    o << p.fi << " " << p.se;
    return o;
}
template<class T> ostream& operator<<(ostream& o, vector<T> &v) {
    bool f=0;
    in(i, v) {
        if (f)
            o << " ";
        f=1;
        o << i;
    }
    return o;
}
template<class T> ostream& operator<<(ostream& o, vector<vector<T>> &v) {
    bool f=0;
    in(i, v) {
        if (f)
            o << '\n';
        f=1;
        o << i;
    }
    return o;
}
template<class H, class T> ostream& operator<<(ostream& o, vector<pair<H, T>> &v) {
    bool f=0;
    in(i, v) {
        if (f)
            o << '\n';
        f=1;
        o << i;
    }
    return o;
}

template<class T> void write(T x) {
    cout << x;
}
template<class H, class... T> void write(const H& h, const T&... t) {
    write(h);
    write(t...);
}

void print() {
    write('\n');
}
template<class H, class... T> void print(const H& h, const T&... t) {
    write(h);
    if (sizeof...(t))
        write(' ');
    print(t...);
}

const ll M=1e9+7, M2=998244353;
const int kx[]={0,1,0,-1}, ky[]={1,0,-1,0};

void fileIO(string filename) {
    freopen((filename+".in").c_str(), "r", stdin);
    freopen((filename+".out").c_str(), "w", stdout);
}

const int mxN=201, mxF=5000;
int n, K, five[mxN], two[mxN], dp[2][mxN][mxF], ans;

int main() {
    cin.tie(0)->sync_with_stdio(0);
    //fileIO("");
    read(n, K);
    FOR(i, 1, n+1) {
        ll a; read(a);
        while (a%2==0)
            ++two[i], a/=2;
        while (a%5==0)
            ++five[i], a/=5;
    }
    memset(dp, -1, sizeof(dp));
    dp[0][0][0]=0;
    FOR(n) FOR(j, K+1) FOR(k, mxF) {
        int c=i&1, b=(i+1)&1;
        if (dp[c][j][k]<0)
            continue;
        ckmax(dp[b][j+1][k+two[i+1]], dp[c][j][k]+five[i+1]);
        ckmax(dp[b][j][k], dp[c][j][k]);
    }
    FOR(mxF)
        ckmax(ans, min(dp[n&1][K][i], i));
    print(ans);
    cerr << "Time elapsed: " << 1.0*clock()/CLOCKS_PER_SEC << "s\n";
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define pb push_back
#define rsz resize
#define ins insert
#define mp make_pair
#define beg(x) x.begin()
#define en(x) x.end()
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define lb lower_bound
#define ub upper_bound
#define umap unordered_map
#define uset unordered_set
#define pqueue priority_queue

//Some for loop stuff stolen from tmw's template
#define for_base(i, a, b, x) for (int i=((a)<(b))?(a):(a)-1; ((a)<(b))?i<(b):i>=(b); ((a)<(b))?i+=(x):i-=(x))
#define FOR1(a) for_base(i, 0, a, 1)
#define FOR2(i, a) for_base(i, 0, a, 1)
#define FOR3(i, a, b) for_base(i, a, b, 1)
#define FOR4(i, a, b, x) for_base(i, a, b, x)
#define FIFTH(a, b, c, d, e, ...) e
#define FOR(...) FIFTH(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define in(i, x) for (auto& i : x)
#define FIT(i, x) for (auto i=(x).begin(); i!=(x).end(); ++i)
#define RIT(i, x) for (auto i=(x).rbegin(); i!=(x).rend(); ++i)

using ll=long long;
using db=double;
using ld=long double;
using pii=pair<int, int>;
using pll=pair<ll, ll>;
using pdd=pair<db, db>;
using vi=vector<int>;
using vl=vector<ll>;
using vd=vector<db>;
using vs=vector<string>;
using vii=vector<pii>;
using vll=vector<pll>;
using vdd=vector<pdd>;
template<class T> using min_heap=pqueue<T, vector<T>, greater<T>>;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<class T> bool ckmin(T& a, const T& b) {return (b<a)?a=b, 1:0;}
template<class T> bool ckmax(T& a, const T& b) {return (a<b)?a=b, 1:0;}

//Read/write stuff also partially stolen from tmw
template<class T> void read(T& x) {
    cin >> x;
}
template<class H, class T> void read(pair<H, T>& p) {
    cin >> p.fi >> p.se;
}
template<class T> void read(vector<T>& v) {
    in(i, v)
        read(i);
}
template<class T> void read(T a[], int n) {
    FOR(n)
        read(a[i]);
}
template<class H, class... T> void read(H& h, T&... t) {
    read(h);
    read(t...);
}

template<class H, class T> ostream& operator<<(ostream& o, const pair<H, T> &p) {
    o << p.fi << " " << p.se;
    return o;
}
template<class T> ostream& operator<<(ostream& o, vector<T> &v) {
    bool f=0;
    in(i, v) {
        if (f)
            o << " ";
        f=1;
        o << i;
    }
    return o;
}
template<class T> ostream& operator<<(ostream& o, vector<vector<T>> &v) {
    bool f=0;
    in(i, v) {
        if (f)
            o << '\n';
        f=1;
        o << i;
    }
    return o;
}
template<class H, class T> ostream& operator<<(ostream& o, vector<pair<H, T>> &v) {
    bool f=0;
    in(i, v) {
        if (f)
            o << '\n';
        f=1;
        o << i;
    }
    return o;
}

template<class T> void write(T x) {
    cout << x;
}
template<class H, class... T> void write(const H& h, const T&... t) {
    write(h);
    write(t...);
}

void print() {
    write('\n');
}
template<class H, class... T> void print(const H& h, const T&... t) {
    write(h);
    if (sizeof...(t))
        write(' ');
    print(t...);
}

const ll M=1e9+7, M2=998244353;
const int kx[]={0,1,0,-1}, ky[]={1,0,-1,0};

void fileIO(string filename) {
    freopen((filename+".in").c_str(), "r", stdin);
    freopen((filename+".out").c_str(), "w", stdout);
}

const int mxN=201, mxF=5000;
int n, K, five[mxN], two[mxN], dp[mxN][mxN][mxF], ans;

int main() {
    cin.tie(0)->sync_with_stdio(0);
    //fileIO("");
    read(n, K);
    FOR(n) {
        ll a; read(a);
        while (a%2==0)
            ++two[i], a/=2;
        while (a%5==0)
            ++five[i], a/=5;
    }
    FOR(n) FOR(j, i+1) FOR(k, mxF) {
        ckmax(dp[i+1][j+1][k+two[i]], dp[i][j][k]+five[i]);
        ckmax(dp[i+1][j][k], dp[i][j][k]);
    }
    FOR(mxF)
        ckmax(ans, min(dp[n][K][i], i));
    print(ans);
    cerr << "Time elapsed: " << 1.0*clock()/CLOCKS_PER_SEC << "s\n";
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define pb push_back
#define rsz resize
#define ins insert
#define mp make_pair
#define beg(x) x.begin()
#define en(x) x.end()
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define lb lower_bound
#define ub upper_bound
#define umap unordered_map
#define uset unordered_set
#define pqueue priority_queue

//Some for loop stuff stolen from tmw's template
#define for_base(i, a, b, x) for (int i=((a)<(b))?(a):(a)-1; ((a)<(b))?i<(b):i>=(b); ((a)<(b))?i+=(x):i-=(x))
#define FOR1(a) for_base(i, 0, a, 1)
#define FOR2(i, a) for_base(i, 0, a, 1)
#define FOR3(i, a, b) for_base(i, a, b, 1)
#define FOR4(i, a, b, x) for_base(i, a, b, x)
#define FIFTH(a, b, c, d, e, ...) e
#define FOR(...) FIFTH(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define in(i, x) for (auto& i : x)
#define FIT(i, x) for (auto i=(x).begin(); i!=(x).end(); ++i)
#define RIT(i, x) for (auto i=(x).rbegin(); i!=(x).rend(); ++i)

using ll=long long;
using db=double;
using ld=long double;
using pii=pair<int, int>;
using pll=pair<ll, ll>;
using pdd=pair<db, db>;
using vi=vector<int>;
using vl=vector<ll>;
using vd=vector<db>;
using vs=vector<string>;
using vii=vector<pii>;
using vll=vector<pll>;
using vdd=vector<pdd>;
template<class T> using min_heap=pqueue<T, vector<T>, greater<T>>;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<class T> bool ckmin(T& a, const T& b) {return (b<a)?a=b, 1:0;}
template<class T> bool ckmax(T& a, const T& b) {return (a<b)?a=b, 1:0;}

//Read/write stuff also partially stolen from tmw
template<class T> void read(T& x) {
    cin >> x;
}
template<class H, class T> void read(pair<H, T>& p) {
    cin >> p.fi >> p.se;
}
template<class T> void read(vector<T>& v) {
    in(i, v)
        read(i);
}
template<class T> void read(T a[], int n) {
    FOR(n)
        read(a[i]);
}
template<class H, class... T> void read(H& h, T&... t) {
    read(h);
    read(t...);
}

template<class H, class T> ostream& operator<<(ostream& o, const pair<H, T> &p) {
    o << p.fi << " " << p.se;
    return o;
}
template<class T> ostream& operator<<(ostream& o, vector<T> &v) {
    bool f=0;
    in(i, v) {
        if (f)
            o << " ";
        f=1;
        o << i;
    }
    return o;
}
template<class T> ostream& operator<<(ostream& o, vector<vector<T>> &v) {
    bool f=0;
    in(i, v) {
        if (f)
            o << '\n';
        f=1;
        o << i;
    }
    return o;
}
template<class H, class T> ostream& operator<<(ostream& o, vector<pair<H, T>> &v) {
    bool f=0;
    in(i, v) {
        if (f)
            o << '\n';
        f=1;
        o << i;
    }
    return o;
}

template<class T> void write(T x) {
    cout << x;
}
template<class H, class... T> void write(const H& h, const T&... t) {
    write(h);
    write(t...);
}

void print() {
    write('\n');
}
template<class H, class... T> void print(const H& h, const T&... t) {
    write(h);
    if (sizeof...(t))
        write(' ');
    print(t...);
}

const ll M=1e9+7, M2=998244353;
const int kx[]={0,1,0,-1}, ky[]={1,0,-1,0};

void fileIO(string filename) {
    freopen((filename+".in").c_str(), "r", stdin);
    freopen((filename+".out").c_str(), "w", stdout);
}

const int mxN=201, mxF=1000;
int n, K, five[mxN], two[mxN], dp[mxN][mxN][mxF], ans;

int main() {
    cin.tie(0)->sync_with_stdio(0);
    //fileIO("");
    read(n, K);
    FOR(n) {
        ll a; read(a);
        while (a%2==0)
            ++two[i], a/=2;
        while (a%5==0)
            ++five[i], a/=5;
    }
    FOR(n) FOR(j, i+1) FOR(k, mxF) {
        ckmax(dp[i+1][j+1][k+two[i]], dp[i][j][k]+five[i]);
        ckmax(dp[i+1][j][k], dp[i][j][k]);
    }
    FOR(mxF)
        ckmax(ans, min(dp[n][K][i], i));
    print(ans);
    cerr << "Time elapsed: " << 1.0*clock()/CLOCKS_PER_SEC << "s\n";
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define pb push_back
#define rsz resize
#define ins insert
#define mp make_pair
#define beg(x) x.begin()
#define en(x) x.end()
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define lb lower_bound
#define ub upper_bound
#define umap unordered_map
#define uset unordered_set
#define pqueue priority_queue

//Some for loop stuff stolen from tmw's template
#define for_base(i, a, b, x) for (int i=((a)<(b))?(a):(a)-1; ((a)<(b))?i<(b):i>=(b); ((a)<(b))?i+=(x):i-=(x))
#define FOR1(a) for_base(i, 0, a, 1)
#define FOR2(i, a) for_base(i, 0, a, 1)
#define FOR3(i, a, b) for_base(i, a, b, 1)
#define FOR4(i, a, b, x) for_base(i, a, b, x)
#define FIFTH(a, b, c, d, e, ...) e
#define FOR(...) FIFTH(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define in(i, x) for (auto& i : x)
#define FIT(i, x) for (auto i=(x).begin(); i!=(x).end(); ++i)
#define RIT(i, x) for (auto i=(x).rbegin(); i!=(x).rend(); ++i)

using ll=long long;
using db=double;
using ld=long double;
using pii=pair<int, int>;
using pll=pair<ll, ll>;
using pdd=pair<db, db>;
using vi=vector<int>;
using vl=vector<ll>;
using vd=vector<db>;
using vs=vector<string>;
using vii=vector<pii>;
using vll=vector<pll>;
using vdd=vector<pdd>;
template<class T> using min_heap=pqueue<T, vector<T>, greater<T>>;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<class T> bool ckmin(T& a, const T& b) {return (b<a)?a=b, 1:0;}
template<class T> bool ckmax(T& a, const T& b) {return (a<b)?a=b, 1:0;}

//Read/write stuff also partially stolen from tmw
template<class T> void read(T& x) {
    cin >> x;
}
template<class H, class T> void read(pair<H, T>& p) {
    cin >> p.fi >> p.se;
}
template<class T> void read(vector<T>& v) {
    in(i, v)
        read(i);
}
template<class T> void read(T a[], int n) {
    FOR(n)
        read(a[i]);
}
template<class H, class... T> void read(H& h, T&... t) {
    read(h);
    read(t...);
}

template<class H, class T> ostream& operator<<(ostream& o, const pair<H, T> &p) {
    o << p.fi << " " << p.se;
    return o;
}
template<class T> ostream& operator<<(ostream& o, vector<T> &v) {
    bool f=0;
    in(i, v) {
        if (f)
            o << " ";
        f=1;
        o << i;
    }
    return o;
}
template<class T> ostream& operator<<(ostream& o, vector<vector<T>> &v) {
    bool f=0;
    in(i, v) {
        if (f)
            o << '\n';
        f=1;
        o << i;
    }
    return o;
}
template<class H, class T> ostream& operator<<(ostream& o, vector<pair<H, T>> &v) {
    bool f=0;
    in(i, v) {
        if (f)
            o << '\n';
        f=1;
        o << i;
    }
    return o;
}

template<class T> void write(T x) {
    cout << x;
}
template<class H, class... T> void write(const H& h, const T&... t) {
    write(h);
    write(t...);
}

void print() {
    write('\n');
}
template<class H, class... T> void print(const H& h, const T&... t) {
    write(h);
    if (sizeof...(t))
        write(' ');
    print(t...);
}

const ll M=1e9+7, M2=998244353;
const int kx[]={0,1,0,-1}, ky[]={1,0,-1,0};

void fileIO(string filename) {
    freopen((filename+".in").c_str(), "r", stdin);
    freopen((filename+".out").c_str(), "w", stdout);
}

const int mxN=201, mxF=6000;
int n, K, five[mxN], two[mxN], dp[2][mxN][mxF], ans;

int main() {
    cin.tie(0)->sync_with_stdio(0);
    //fileIO("");
    read(n, K);
    FOR(n) {
        ll a; read(a);
        while (a%2==0)
            ++two[i], a/=2;
        while (a%5==0)
            ++five[i], a/=5;
    }
    FOR(n) FOR(j, i+1) FOR(k, mxF) {
        int c=i&1, x=(i+1)&1;
        ckmax(dp[x][j+1][k+two[i]], dp[c][j][k]+five[i]);
        ckmax(dp[x][j][k], dp[c][j][k]);
    }
    FOR(mxF)
        ckmax(ans, min(dp[n&1][K][i], i));
    print(ans);
    cerr << "Time elapsed: " << 1.0*clock()/CLOCKS_PER_SEC << "s\n";
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define pb push_back
#define rsz resize
#define ins insert
#define mp make_pair
#define beg(x) x.begin()
#define en(x) x.end()
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define lb lower_bound
#define ub upper_bound
#define umap unordered_map
#define uset unordered_set
#define pqueue priority_queue

//Some for loop stuff stolen from tmw's template
#define for_base(i, a, b, x) for (int i=((a)<(b))?(a):(a)-1; ((a)<(b))?i<(b):i>=(b); ((a)<(b))?i+=(x):i-=(x))
#define FOR1(a) for_base(i, 0, a, 1)
#define FOR2(i, a) for_base(i, 0, a, 1)
#define FOR3(i, a, b) for_base(i, a, b, 1)
#define FOR4(i, a, b, x) for_base(i, a, b, x)
#define FIFTH(a, b, c, d, e, ...) e
#define FOR(...) FIFTH(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define in(i, x) for (auto& i : x)
#define FIT(i, x) for (auto i=(x).begin(); i!=(x).end(); ++i)
#define RIT(i, x) for (auto i=(x).rbegin(); i!=(x).rend(); ++i)

using ll=long long;
using db=double;
using ld=long double;
using pii=pair<int, int>;
using pll=pair<ll, ll>;
using pdd=pair<db, db>;
using vi=vector<int>;
using vl=vector<ll>;
using vd=vector<db>;
using vs=vector<string>;
using vii=vector<pii>;
using vll=vector<pll>;
using vdd=vector<pdd>;
template<class T> using min_heap=pqueue<T, vector<T>, greater<T>>;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<class T> bool ckmin(T& a, const T& b) {return (b<a)?a=b, 1:0;}
template<class T> bool ckmax(T& a, const T& b) {return (a<b)?a=b, 1:0;}

//Read/write stuff also partially stolen from tmw
template<class T> void read(T& x) {
    cin >> x;
}
template<class H, class T> void read(pair<H, T>& p) {
    cin >> p.fi >> p.se;
}
template<class T> void read(vector<T>& v) {
    in(i, v)
        read(i);
}
template<class T> void read(T a[], int n) {
    FOR(n)
        read(a[i]);
}
template<class H, class... T> void read(H& h, T&... t) {
    read(h);
    read(t...);
}

template<class H, class T> ostream& operator<<(ostream& o, const pair<H, T> &p) {
    o << p.fi << " " << p.se;
    return o;
}
template<class T> ostream& operator<<(ostream& o, vector<T> &v) {
    bool f=0;
    in(i, v) {
        if (f)
            o << " ";
        f=1;
        o << i;
    }
    return o;
}
template<class T> ostream& operator<<(ostream& o, vector<vector<T>> &v) {
    bool f=0;
    in(i, v) {
        if (f)
            o << '\n';
        f=1;
        o << i;
    }
    return o;
}
template<class H, class T> ostream& operator<<(ostream& o, vector<pair<H, T>> &v) {
    bool f=0;
    in(i, v) {
        if (f)
            o << '\n';
        f=1;
        o << i;
    }
    return o;
}

template<class T> void write(T x) {
    cout << x;
}
template<class H, class... T> void write(const H& h, const T&... t) {
    write(h);
    write(t...);
}

void print() {
    write('\n');
}
template<class H, class... T> void print(const H& h, const T&... t) {
    write(h);
    if (sizeof...(t))
        write(' ');
    print(t...);
}

const ll M=1e9+7, M2=998244353;
const int kx[]={0,1,0,-1}, ky[]={1,0,-1,0};

void fileIO(string filename) {
    freopen((filename+".in").c_str(), "r", stdin);
    freopen((filename+".out").c_str(), "w", stdout);
}

const int mxN=201, mxF=30;
int n, K, five[mxN], two[mxN], dp[mxN][mxN][mxF], ans;

int main() {
    cin.tie(0)->sync_with_stdio(0);
    //fileIO("");
    read(n, K);
    FOR(n) {
        ll a; read(a);
        while (a%2==0)
            ++two[i], a/=2;
        while (a%5==0)
            ++five[i], a/=5;
    }
    FOR(n) FOR(j, i+1) FOR(k, mxF) {
        ckmax(dp[i+1][j+1][k+two[i]], dp[i][j][k]+five[i]);
        ckmax(dp[i+1][j][k], dp[i][j][k]);
    }
    FOR(mxF)
        ckmax(ans, min(dp[n][K][i], i));
    print(ans);
    cerr << "Time elapsed: " << 1.0*clock()/CLOCKS_PER_SEC << "s\n";
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define pb push_back
#define rsz resize
#define ins insert
#define mp make_pair
#define beg(x) x.begin()
#define en(x) x.end()
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define lb lower_bound
#define ub upper_bound
#define umap unordered_map
#define uset unordered_set
#define pqueue priority_queue

//Some for loop stuff stolen from tmw's template
#define for_base(i, a, b, x) for (int i=((a)<(b))?(a):(a)-1; ((a)<(b))?i<(b):i>=(b); ((a)<(b))?i+=(x):i-=(x))
#define FOR1(a) for_base(i, 0, a, 1)
#define FOR2(i, a) for_base(i, 0, a, 1)
#define FOR3(i, a, b) for_base(i, a, b, 1)
#define FOR4(i, a, b, x) for_base(i, a, b, x)
#define FIFTH(a, b, c, d, e, ...) e
#define FOR(...) FIFTH(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define in(i, x) for (auto& i : x)
#define FIT(i, x) for (auto i=(x).begin(); i!=(x).end(); ++i)
#define RIT(i, x) for (auto i=(x).rbegin(); i!=(x).rend(); ++i)

using ll=long long;
using db=double;
using ld=long double;
using pii=pair<int, int>;
using pll=pair<ll, ll>;
using pdd=pair<db, db>;
using vi=vector<int>;
using vl=vector<ll>;
using vd=vector<db>;
using vs=vector<string>;
using vii=vector<pii>;
using vll=vector<pll>;
using vdd=vector<pdd>;
template<class T> using min_heap=pqueue<T, vector<T>, greater<T>>;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<class T> bool ckmin(T& a, const T& b) {return (b<a)?a=b, 1:0;}
template<class T> bool ckmax(T& a, const T& b) {return (a<b)?a=b, 1:0;}

//Read/write stuff also partially stolen from tmw
template<class T> void read(T& x) {
    cin >> x;
}
template<class H, class T> void read(pair<H, T>& p) {
    cin >> p.fi >> p.se;
}
template<class T> void read(vector<T>& v) {
    in(i, v)
        read(i);
}
template<class T> void read(T a[], int n) {
    FOR(n)
        read(a[i]);
}
template<class H, class... T> void read(H& h, T&... t) {
    read(h);
    read(t...);
}

template<class H, class T> ostream& operator<<(ostream& o, const pair<H, T> &p) {
    o << p.fi << " " << p.se;
    return o;
}
template<class T> ostream& operator<<(ostream& o, vector<T> &v) {
    bool f=0;
    in(i, v) {
        if (f)
            o << " ";
        f=1;
        o << i;
    }
    return o;
}
template<class T> ostream& operator<<(ostream& o, vector<vector<T>> &v) {
    bool f=0;
    in(i, v) {
        if (f)
            o << '\n';
        f=1;
        o << i;
    }
    return o;
}
template<class H, class T> ostream& operator<<(ostream& o, vector<pair<H, T>> &v) {
    bool f=0;
    in(i, v) {
        if (f)
            o << '\n';
        f=1;
        o << i;
    }
    return o;
}

template<class T> void write(T x) {
    cout << x;
}
template<class H, class... T> void write(const H& h, const T&... t) {
    write(h);
    write(t...);
}

void print() {
    write('\n');
}
template<class H, class... T> void print(const H& h, const T&... t) {
    write(h);
    if (sizeof...(t))
        write(' ');
    print(t...);
}

const ll M=1e9+7, M2=998244353;
const int kx[]={0,1,0,-1}, ky[]={1,0,-1,0};

void fileIO(string filename) {
    freopen((filename+".in").c_str(), "r", stdin);
    freopen((filename+".out").c_str(), "w", stdout);
}

const int mxN=201, mxF=6000;
int n, K, five[mxN], two[mxN], dp[mxN][mxF], ans;

int main() {
    cin.tie(0)->sync_with_stdio(0);
    //fileIO("");
    read(n, K);
    FOR(n) {
        ll a; read(a);
        while (a%2==0)
            ++two[i], a/=2;
        while (a%5==0)
            ++five[i], a/=5;
    }
    memset(dp, -1, sizeof(dp));
    dp[0][0]=0;
    int cmax=30;
    FOR(n) {
        FOR(j, K+1, 0) FOR(k, cmax, 0) {
            if (j && k>=five[i] && dp[j-1][k-five[i]]>=0)
                ckmax(dp[j][k], dp[j-1][k-five[i]]+two[i]);
            if (dp[j][k+1]>=0)
                ckmax(dp[j][k], dp[j][k+1]);
            //print(j, k, dp[j][k]);
        }
        cmax+=30;
    }
    FOR(mxF)
        ckmax(ans, min(dp[K][i], i));
    print(ans);
    cerr << "Time elapsed: " << 1.0*clock()/CLOCKS_PER_SEC << "s\n";
}