#include<bits/stdc++.h>
using namespace std;
#define _rep(i, x, y) for(int i = (int)x; i < (int)y; ++i)
#define _dep(i,x,y) for(int i = (int)x; i > (int)y; i--)
#define PII pair<int,int>
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define PQ priority_queue
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VII;
typedef vector<ll> VL;
typedef vector<vector<ll>> VLL;
constexpr int mod = 1e9 + 7;
constexpr int KINF = 0x3f3f3f3f;
constexpr double eps = 1e-7;
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	ll A, B;
	cin >> A >> B;
	// gcd(x, y) = gcd(x - y, y) <= x - y <= B - A <= 72   (x > y)
	// 所以A到B之间任意两个数的最大公因子必然是小于等于72的质数的倍数
	// 于是问题就可以转化为存在共同公因子的数不超过两个便是合法,20的范围用状压DP即可解决
	int p[20] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71};
	VI dp(1 << 20);
	dp[0] = 1;
	for(ll x = A; x <= B; x ++){
		int mask = 0;
		_rep(i, 0, 20)
			if(x % p[i] == 0) mask |= (1 << i);// 求出x所含的质因子
		_rep(j, 0, (1 << 20)){
			if(j & mask) continue;// 存在某一位相同(即之前的数与当前数有共同公因子)
			dp[j | mask] += dp[j];
		}
	}
	cout << accumulate(all(dp), 0) << endl;
	return 0;
} 
// 小心左移运算符导致的int溢出
// dp记得处理非法状态
// resize并不会初始化数组
// 全局函数一定要记得inline
// 带空格字符串不能直接cin,要用getline


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

int main(){
    int n, k;
    cin >> n >> k;
    long t[n][n];   //t[0]= city1
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            cin >> t[i][j];
        }
    }
    int p[n];   //p[0] = city 1
    for(int i=0; i<n; i++){
        p[i]=i;
    }
    long long ans=0, ret;
    int i;
    do{
        ret=0;
        for(i=0; i<n-1; i++){
            ret += t[p[i]][p[i+1]];
        }
        //last to city1
        ret += t[p[i]][0];
        if(ret==k) ans++;
    }while(next_permutation(p+1, p+n));
    cout << ans;
    return 0;
}