#include <bits/stdc++.h>
using namespace std;
inline int add(int a, int b, int m = 1000000007) {
  a += b;
  if (a >= m) a -= m;
  return a;
}
inline int mul(int a, int b, int m = 1000000007) {
  return (int)(((long long)a * (long long)b) % m);
}
inline int norm(int x, int m = 1000000007) {
  if (x >= m) x %= m;
  if (x < 0) x += m;
  return x;
}
inline int neg(int x, int m = 1000000007) {
  x = -x;
  return norm(x);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s1, s2;
  cin >> s1 >> s2;
  if (s1.length() < s2.length()) s1.swap(s2);
  int n = s1.length(), m = s2.length();
  for (int i = 0; i <= m - 1; ++i) {
    if (s2[i] != s1[i]) {
      cout << 0;
      return 0;
    }
  }
  vector<int> div;
  for (int i = 1; i <= n; ++i)
    if (n % i == 0) div.push_back(i);
  int ans = 0;
  for (auto it = (div).begin(); it != (div).end(); ++it) {
    int k = *it;
    if (m % k != 0) continue;
    bool flag = 1;
    for (int i = 0; i <= n - 1; ++i) {
      if (s1[i] != s1[i % k]) {
        flag = 0;
        break;
      }
    }
    if (flag) ans++;
  }
  cout << ans;
}
