#include <bits/stdc++.h>
using namespace std;
string a, b;
bool check1(long long len) {
  for (long long i = 0; i < a.size(); i++) {
    if (a[i] != a[i % len]) return false;
  }
  return true;
}
bool check2(long long len) {
  for (long long i = 0; i < b.size(); i++) {
    if (b[i] != b[i % len]) return false;
  }
  return true;
}
bool check3(long long len) {
  for (long long i = 0; i < len; i++)
    if (a[i] != b[i]) return false;
  return true;
}
long long ans;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> a >> b;
  for (long long i = 1; i <= 100000; i++) {
    if (a.size() % i == 0 && b.size() % i == 0 && check1(i) && check2(i) &&
        check3(i))
      ans++;
  }
  cout << ans << endl;
}
