#include <bits/stdc++.h>
using namespace std;
const int MN = 1e9;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string a, b;
  cin >> a >> b;
  if (a.size() < b.size()) swap(a, b);
  bool ok = 1;
  int ans = 999999999;
  for (int i = 0, cnt = 0; i < a.size(); ++i) {
    if (a[i] == b[cnt]) {
      ++cnt;
      if (cnt == b.size() || i + 1 == a.size()) ans = min(ans, cnt), cnt = 0;
    } else {
      ok ^= 1;
      break;
    }
  }
  int check = 0;
  for (int i = 0, cnt = 0; i < b.size(); ++i) {
    if (a[i] == a[cnt]) {
      ++cnt;
      if (cnt == ans) cnt = 0, ++check;
    } else
      ok = 0;
  }
  if (check * ans != b.size()) ok = 0;
  if (ok) {
    string c;
    long long x = 0;
    for (int i = 0; i < ans; ++i) {
      c += b[i];
      if (ans % (i + 1) != 0)
        continue;
      else {
        int ct = 0;
        for (int j = 0, cnt = 0; j < ans; ++j) {
          if (c[cnt] == b[j])
            if (cnt + 1 == c.size()) {
              ++ct;
              cnt = 0;
            } else
              ++cnt;
          else
            break;
        }
        if (ct * c.size() == ans) ++x;
      }
    }
    cout << x;
  } else
    cout << 0;
}
