#include <bits/stdc++.h>
using namespace std;
const long long M = 1000000007;
string a, b;
bool isDivisible(string s, int len) {
  bool divisible = true;
  for (int i = 0; i < s.length(); i++) {
    if (a[i % len] != s[i]) {
      divisible = false;
      break;
    }
  }
  return divisible;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> a >> b;
  long long ans = 0;
  for (int i = 1; i <= min((int)a.size(), (int)b.size()); i++) {
    if (((int)a.size()) % i == 0 && ((int)b.size()) % i == 0) {
      if (isDivisible(a, i) && isDivisible(b, i)) {
        ans++;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
