#include <bits/stdc++.h>
using namespace std;
int next1[100005], next2[100005];
char s1[100005], s2[100005];
void get_next() {
  int i = 1, j = 0;
  next1[i] = j;
  while (s1[i]) {
    if (j == 0 || s1[i] == s1[j])
      next1[++i] = ++j;
    else
      j = next1[j];
  }
  i = 1, j = 0;
  next2[i] = j;
  while (s2[i]) {
    if (j == 0 || s2[i] == s2[j])
      next2[++i] = ++j;
    else
      j = next2[j];
  }
}
int main() {
  cin >> (s1 + 1) >> (s2 + 1);
  get_next();
  int l1 = strlen(s1 + 1), l2 = strlen(s2 + 1), t1, t2, ans = 0;
  t1 = l1 - next1[l1], t2 = l2 - next2[l2];
  for (int i = t1 + 1; i <= l1; ++i)
    if (s1[i] != s1[i - t1]) {
      t1 = l1;
      break;
    }
  for (int i = t2 + 1; i <= l2; ++i)
    if (s2[i] != s2[i - t2]) {
      t2 = l2;
      break;
    }
  if (l1 % t1) t1 = l1;
  if (l2 % t2) t2 = l2;
  for (int i = 1, j = 0; i <= l1 && i <= l2; ++i)
    if (s1[i] == s2[i]) {
      ++j;
      if (l1 % j != 0 || l2 % j != 0) continue;
      if (t1 > j || t2 > j) continue;
      if (j % t1 != 0 || j % t2 != 0) continue;
      ++ans;
    } else
      break;
  cout << ans << endl;
}
