#include <bits/stdc++.h>
using namespace std;
set<int> tried;
string a, b;
bool test(int x) {
  if (tried.find(x) != tried.end()) {
    return 0;
  }
  tried.insert(x);
  if (a.size() % x != 0) {
    return 0;
    ;
  }
  if (b.size() % x != 0) {
    return 0;
    ;
  }
  string sa = "", sb = "";
  for (int i = 0; i < x; i++) {
    sa += a[i];
    sb += b[i];
  }
  if (sa != sb) {
    return 0;
  }
  bool ok = true;
  for (int i = 0; i < a.size(); i++) {
    if (a[i] != a[i % x]) {
      ok = false;
    }
  }
  for (int i = 0; i < b.size(); i++) {
    if (b[i] != b[i % x]) {
      ok = false;
    }
  }
  return ok;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> a >> b;
  int cnt = 0;
  for (int x = 1; x * x <= min(a.size(), b.size()); x++) {
    cnt += test(x);
    if (a.size() % x == 0) {
      cnt += test(a.size() / x);
    }
    if (b.size() % x == 0) {
      cnt += test(b.size() / x);
    }
  }
  cout << cnt << "\n";
}
