#include <bits/stdc++.h>
using namespace std;
bool isprime(long long n) {
  for (long long i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
long long factorial(long long n) {
  return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long lcm(long long a, long long b) { return (a / gcd(a, b) * b); }
long long max(long long a, long long b) {
  long long sol = a > b ? a : b;
  return sol;
}
long long min(long long a, long long b) {
  long long sol = a < b ? a : b;
  return sol;
}
long long inf = 1000000005;
vector<long long> v(1000001, 0);
inline void solve() {
  string s1, s2;
  cin >> s1 >> s2;
  if (s2.size() < s1.size()) {
    swap(s1, s2);
  }
  long long cnt = 0;
  for (long long i = 1; i <= s1.size(); i++) {
    if (s1.size() % i == 0 && s2.size() % i == 0) {
      string s, t;
      for (long long j = 1; j <= s1.size() / i; j++) s += s1.substr(0, i);
      for (long long j = 1; j <= s2.size() / i; j++) t += s1.substr(0, i);
      if (s == s1 && t == s2) {
        cnt++;
      }
    }
  }
  cout << cnt;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  solve();
}
