#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s1, s2;
  cin >> s1 >> s2;
  int n = s1.length(), m = s2.length();
  if (n > m) {
    swap(s1, s2);
    swap(n, m);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    string s;
    if (n % i == 0 && m % i == 0) {
      string temp = s1.substr(0, i);
      int num = m / i;
      int num1 = n / i;
      for (int j = 0; j < num; j++) {
        s += temp;
        if (j == num1 - 1) {
          if (s != s1) break;
        }
        if (j == num - 1) {
          if (s == s2) ans++;
        }
      }
    }
  }
  cout << ans;
  return 0;
}
