#include <bits/stdc++.h>
using namespace std;
int main(void) {
  string s1, s2;
  cin >> s1 >> s2;
  long long int ans = 0;
  set<long long int> div1, div2, res;
  for (long long int i = 1; i <= sqrt(s1.length()); i++) {
    if (s1.length() % i == 0) {
      div1.insert(i);
      div1.insert(s1.length() / i);
    }
  }
  for (long long int i = 1; i <= sqrt(s2.length()); i++) {
    if (s2.length() % i == 0) {
      div2.insert(i);
      div2.insert(s2.length() / i);
    }
  }
  for (auto it : div1) {
    if (div2.find(it) != div2.end()) res.insert(it);
  }
  for (auto it : res) {
    string temp1 = "", temp2 = "", temp3 = "";
    for (long long int i = 0; i < it; i++) temp1 += s1[i];
    for (long long int i = 1; i <= s1.length() / it; i++) temp2 += temp1;
    for (long long int i = 1; i <= s2.length() / it; i++) temp3 += temp1;
    if (s1 == temp2 && s2 == temp3) ans++;
  }
  cout << ans << endl;
  return 0;
}
