#include <bits/stdc++.h>
using namespace std;
long long choose(long long n, long long k);
bool isprime(long long n);
long long power(long long x, long long y, long long p);
int maxi(int Count, ...);
int mini(int Count, ...);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s1, s2;
  cin >> s1 >> s2;
  long long n = s1.length(), m = s2.length(), ans = 0;
  string t = "";
  for (int i = 0; i < min(n, m); i++) {
    t += s1[i];
    if (n % (t.length()) == 0) {
      string t1 = t;
      long long f = 0;
      for (int j = 0; j < n; j += t.length()) {
        if (s1.substr(j, t.length()) != t1) {
          f = 1;
          break;
        }
      }
      for (int j = 0; j < m; j += t.length()) {
        if (s2.substr(j, t.length()) != t1) {
          f = 1;
          break;
        }
      }
      if (!f) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
long long choose(long long n, long long k) {
  if (k == 0) return 1;
  return (n * choose(n - 1, k - 1)) / k;
}
bool isprime(long long n) {
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int maxi(int Count, ...) {
  va_list Numbers;
  va_start(Numbers, Count);
  int ma = INT_MIN;
  for (int i = 0; i < Count; i++) ma = max(ma, va_arg(Numbers, int));
  va_end(Numbers);
  return ma;
}
int mini(int Count, ...) {
  va_list Numbers;
  va_start(Numbers, Count);
  int mi = INT_MAX;
  for (int i = 0; i < Count; i++) mi = min(mi, va_arg(Numbers, int));
  va_end(Numbers);
  return mi;
}
