#include <bits/stdc++.h>
using namespace std;
const int mx = 1e5 + 10;
const double eps = 1e-9;
const int inf = 1e9;
string a, b;
int main() {
  cin >> a >> b;
  bool ok = 0;
  int n1 = a.length(), n2 = b.length(), ans = 0;
  string tmp = a + b;
  int n3 = tmp.length();
  for (int i = 1; i <= min(n1, n2); i++) {
    ok = 1;
    if (n1 % i == 0 && n2 % i == 0) {
      for (int j = i; j <= n3 - i; j += i) {
        if (tmp.substr(0, i) != tmp.substr(j, i)) {
          ok = 0;
        }
      }
      if (ok) ans++;
    }
  }
  cout << ans << endl;
}
