#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6;
const long long z = 131, MOD = 1e9 + 21;
long long Z[MAXN + 1];
string a, b;
vector<int> divisores;
vector<long long> v;
int g, r, l;
long long h;
void fillZ() {
  Z[0] = 1;
  for (int n = 1; n <= MAXN; ++n) Z[n] = z * Z[n - 1] % MOD;
}
struct RollingHashing {
  vector<long long> H;
  RollingHashing(string &S) {
    int N = S.length();
    H.resize(N + 1);
    H[N] = 0;
    for (int i = N - 1; i >= 0; --i) H[i] = (S[i] + z * H[i + 1]) % MOD;
  }
  long long hash(int i, int k) {
    long long ans = (H[i] - Z[k] * H[i + k] % MOD);
    return ans >= 0 ? ans : ans + MOD;
  }
};
int gcd(int a, int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
void divs(int a, int b, vector<int> &S) {
  int g = gcd(a, b);
  for (int i = 1; i <= sqrt(g); i++) {
    if (g % i == 0) {
      r = g / i;
      if (r == i)
        S.push_back(i);
      else {
        S.push_back(i);
        S.push_back(r);
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  fillZ();
  cin >> a;
  cin >> b;
  struct RollingHashing r1 = RollingHashing(a);
  struct RollingHashing r2 = RollingHashing(b);
  divisores.clear();
  divs(a.length(), b.length(), divisores);
  int res = 0;
  if (a.length() < b.length()) {
    for (int i = 0; i < divisores.size(); i++) {
      v.clear();
      l = divisores[i];
      h = r1.hash(0, l);
      int j;
      for (j = 0; j < b.length() / l; j++) {
        if (r2.hash(j * l, l) != h) {
          break;
        }
      }
      if (j == b.length() / l) {
        res += 1;
      }
    }
  } else {
    for (int i = 0; i < divisores.size(); i++) {
      v.clear();
      l = divisores[i];
      h = r2.hash(0, l);
      int j;
      for (j = 0; j < a.length() / l; j++) {
        if (r1.hash(j * l, l) != h) {
          break;
        }
      }
      if (j == a.length() / l) {
        res += 1;
      }
    }
  }
  cout << res;
  return 0;
}
