#include <bits/stdc++.h>
using namespace std;
using namespace std;
const long double PI = acos(-1.0);
long long fastmodpow(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return ans;
}
long long prefh1[100010];
long long prefh2[100010];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  ;
  int N, M, i, j;
  string s1, s2;
  cin >> s1 >> s2;
  N = s1.size();
  M = s2.size();
  if (N > M) {
    int tmp = N;
    N = M;
    M = tmp;
    string tmp1 = s1;
    s1 = s2;
    s2 = tmp1;
  }
  prefh1[0] = s1[0] - 'a';
  for (i = 1; i < N; ++i)
    prefh1[i] = (31 * prefh1[i - 1] + s1[i] - 'a') % 1000000007;
  prefh2[0] = s2[0] - 'a';
  for (i = 1; i < M; ++i)
    prefh2[i] = (31 * prefh2[i - 1] + s2[i] - 'a') % 1000000007;
  int ans = 0;
  for (i = 1; i <= N; ++i) {
    if ((N % i) || (M % i)) continue;
    if (prefh1[i - 1] != prefh2[i - 1]) continue;
    long long chk = prefh1[i - 1];
    bool fl = 1;
    for (j = i; j < N; j += i) {
      long long hh = (prefh1[j + i - 1] -
                      (prefh1[j - 1] * fastmodpow(31, i)) % 1000000007) %
                     1000000007;
      if (hh < 0) hh += 1000000007;
      if (hh != chk) {
        fl = 0;
        break;
      }
    }
    for (j = i; j < M; j += i) {
      long long hh = (prefh2[j + i - 1] -
                      (prefh2[j - 1] * fastmodpow(31, i)) % 1000000007) %
                     1000000007;
      if (hh < 0) hh += 1000000007;
      if (hh != chk) {
        fl = 0;
        break;
      }
    }
    if (fl) ++ans;
  }
  cout << ans;
  return 0;
}
