#include <bits/stdc++.h>
using namespace std;
bool check(string s, int a) {
  for (int i = 0; i < a; i++) {
    for (int j = 1; j < s.length() / a; j++) {
      if (s[i] != s[j * a + i]) return false;
    }
  }
  return true;
}
int main() {
  string a, b;
  cin >> a >> b;
  int l1 = a.length();
  int l2 = b.length();
  string s = a + b;
  int count = 0;
  for (int i = 1; i <= min(l1, l2); i++) {
    if ((l1 % i == 0) && (l2 % i == 0)) {
      if (check(s, i)) count++;
    }
  }
  cout << count << endl;
  return 0;
}
