#include <bits/stdc++.h>
using namespace std;
struct Hash {
  int hash_sum;
  int hash_ord;
};
Hash get_hash(string s) {
  int sum1 = 0;
  int sum2 = 0;
  int idx = 1;
  Hash hash;
  for (char& c : s) {
    sum1 += c;
    sum2 += c * idx;
    ++idx;
  }
  hash.hash_sum = sum1;
  hash.hash_ord = sum2;
  return hash;
}
bool all_the_same(string s) {
  char first = s[0];
  for (char& c : s) {
    if (first != c) {
      return false;
    }
  }
  return true;
}
int main() {
  string s1;
  string s2;
  int res = 0;
  cin >> s1;
  cin >> s2;
  int s1_len = s1.size();
  int s2_len = s2.size();
  int min_len = s1_len < s2_len ? s1_len : s2_len;
  int max_len = min_len == s1_len ? s2_len : s1_len;
  string min_str = min_len == s1_len ? s1 : s2;
  string max_str = min_len == s1_len ? s2 : s1;
  int idx = min_len;
  while (idx > 0) {
    if (min_len % idx == 0 && max_len % idx == 0) {
      int fac_min = min_len / idx;
      int fac_max = max_len / idx;
      Hash hash_substr = get_hash(min_str.substr(0, idx));
      Hash hash_min_str = get_hash(min_str);
      Hash hash_max_str = get_hash(max_str);
      if (hash_substr.hash_sum * fac_min == hash_min_str.hash_sum &&
          hash_substr.hash_sum * fac_max == hash_max_str.hash_sum) {
        if (hash_substr.hash_ord == get_hash(max_str.substr(0, idx)).hash_ord) {
          res += 1;
        }
      }
    }
    --idx;
  }
  cout << res << endl;
  return 0;
}
