#include <bits/stdc++.h>
using namespace std;
const long long INF = LLONG_MAX;
const long long SZ = 4e5 + 5;
const long long mod = 1e9 + 7;
const long long b1 = 1e4 + 7;
const long long b2 = 1e9 + 87;
const long long mod1 = 998244353;
const long long mod2 = 1e9 + 9;
long long pw1[SZ], pw2[SZ];
long long h1[3][SZ], h2[3][SZ];
long long szs[3];
void cal_pwr() {
  pw1[0] = pw2[0] = 1;
  for (long long i = 1; i < SZ; i++) {
    pw1[i] = (pw1[i - 1] * b1) % mod1;
    pw2[i] = (pw2[i - 1] * b2) % mod2;
  }
}
void build_hash(string s, long long id) {
  long long i, sz = s.size();
  szs[id] = sz;
  h1[id][0] = h2[id][0] = 0;
  for (i = 0; i < sz; i++) {
    h1[id][i + 1] = ((h1[id][i] * b1) + s[i]) % mod1;
    h2[id][i + 1] = ((h2[id][i] * b2) + s[i]) % mod2;
  }
}
long long get_hash(long long l, long long r, long long id) {
  long long v1 = (h1[id][r] - (h1[id][l - 1] * pw1[r - l + 1])) % mod1;
  if (v1 < 0) v1 += mod1;
  long long v2 = (h2[id][r] - (h2[id][l - 1] * pw2[r - l + 1])) % mod2;
  if (v2 < 0) v2 += mod2;
  return ((v1 << 32LL) | v2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cal_pwr();
  long long t = 0, n, x, y, z, i, j, k, g, p, q, ans = 0, sum = 0, c = 0;
  string s, s1, s2;
  cin >> s1 >> s2;
  build_hash(s1, 0);
  build_hash(s2, 1);
  long long n1 = s1.size();
  vector<long long> d;
  for (i = 1; i * i <= n1; i++) {
    if (n1 % i == 0) {
      j = n1 / i;
      d.push_back(i);
      if (i != j) d.push_back(j);
    }
  }
  long long n2 = s2.size();
  for (i = 0; i < d.size(); i++) {
    if (n2 % d[i]) continue;
    long long v1 = get_hash(1, d[i], 0);
    long long v2 = get_hash(1, d[i], 1);
    if (v1 != v2) continue;
    bool f = 1;
    for (j = d[i] + d[i]; j <= n1; j += d[i]) {
      x = get_hash(j - d[i] + 1, j, 0);
      if (x != v1) {
        f = 0;
        break;
      }
    }
    if (!f) continue;
    for (j = d[i] + d[i]; j <= n2; j += d[i]) {
      x = get_hash(j - d[i] + 1, j, 1);
      if (x != v1) {
        f = 0;
        break;
      }
    }
    if (f) c++;
  }
  cout << c << "\n";
  return 0;
}
