#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e6 + 5, MOD = 1e9 + 9, eps = 1e-7;
string T, S;
int n, m;
long long h[maxN], f[maxN];
int B = 31;
long long fastPow(long long x, long long n) {
  long long ret = 1;
  while (n) {
    if (n & 1) ret = ret * x % MOD;
    n >>= 1, x = x * x % MOD;
  }
  return ret;
}
void buildHash() {
  h[n - 1] = T[n - 1];
  for (int i = n - 2; i >= 0; i--) h[i] = (B * h[i + 1] + T[i]) % MOD;
  f[m - 1] = S[m - 1];
  for (int i = m - 2; i >= 0; i--) f[i] = (B * f[i + 1] + S[i]) % MOD;
}
long long substrhashT(int i, int j) {
  return (h[i] - (h[j + 1] * fastPow(B, j + 1 - i)) % MOD + MOD) % MOD;
}
long long substrhashS(int i, int j) {
  return (f[i] - (f[j + 1] * fastPow(B, j + 1 - i)) % MOD + MOD) % MOD;
}
bool stringDivisorT(int div) {
  long long sub = substrhashT(0, div - 1), aux;
  for (int j = div; j < n; j += div) {
    aux = substrhashT(j, j + div - 1);
    if (aux != sub) return false;
  }
  return true;
}
bool stringDivisorS(int div) {
  long long sub = substrhashS(0, div - 1), aux;
  for (int j = div; j < m; j += div) {
    aux = substrhashS(j, j + div - 1);
    if (aux != sub) return false;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> T >> S;
  n = T.length();
  m = S.length();
  buildHash();
  set<string> divT, divS;
  for (int i = 1; i <= n; i++) {
    if (n % i == 0 && stringDivisorT(i)) {
      divT.insert(T.substr(0, i));
    }
  }
  for (int i = 1; i <= m; i++) {
    if (m % i == 0 && stringDivisorS(i)) {
      divS.insert(S.substr(0, i));
    }
  }
  int ans = 0;
  for (string str : divT) {
    if (divS.count(str)) ans++;
  }
  cout << ans << '\n';
  return 0;
}
