#include <iostream>
#define PB 99991
#define MOD 1000000007
#define MAX 100000
#define ll long long
using namespace std;
ll ppow[MAX+1];
ll h1[MAX+1];
ll h2[MAX+1];
string s1, s2;
int main()
{
ppow[0] = 1;
for (int i = 1; i < MAX+1; ++i)
ppow[i] = (ppow[i-1] * PB) % MOD;
cin >> s1; cin >> s2;
int l1 = s1.size(), l2 = s2.size();
h1[0] = s1[0];
//cout << h1[0] << " ";
for (int i = 1; i < l1; ++i)
{
h1[i] = (((h1[i-1] * PB) % MOD) + s1[i]) % MOD;
//cout << h1[i] << " " ;
}
//cout << '\n';
h2[0] = s2[0];
//cout << h2[0] << " ";
for (int i = 1; i < l2; ++i)
{
h2[i] = (((h2[i-1] * PB) % MOD) + s2[i]) % MOD;
//cout << h2[i] << " " ;
}
//cout << '\n';
int ans = 0;
for (int i = 1; i <= l1; ++i)
{
if (l1 % i == 0 && l2 % i == 0)
{
bool flag = true;
ll temp = h1[i-1];
for (int j = 0; j < l1; j = j + i)
{
if (!j)
{
if (temp != h1[j+i-1])
flag = false;
}
else if (temp != (h1[j+i-1] - ((h1[j-1] * ppow[i]) % MOD)))
flag = false;
}
for (int j = 0; j < l2; j = j + i)
{
if (i == 4)
cout << (h2[j+i-1] - ((h2[j-1] * ppow[i]) % MOD)) << " " << "check" << '\n';
if (!j)
{
if (temp != h2[j+i-1])
flag = false;
}
else if (temp != (h2[j+i-1] - ((h2[j-1] * ppow[i]) % MOD)))
flag = false;
}
ans += flag;
}
}
cout << ans;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojZGVmaW5lIFBCIDk5OTkxCiNkZWZpbmUgTU9EIDEwMDAwMDAwMDcKI2RlZmluZSBNQVggMTAwMDAwCiNkZWZpbmUgbGwgbG9uZyBsb25nCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpsbCBwcG93W01BWCsxXTsKbGwgaDFbTUFYKzFdOwpsbCBoMltNQVgrMV07CnN0cmluZyBzMSwgczI7CgppbnQgbWFpbigpIAp7CiAgICBwcG93WzBdID0gMTsKICAgIGZvciAoaW50IGkgPSAxOyBpIDwgTUFYKzE7ICsraSkKICAgICAgICBwcG93W2ldID0gKHBwb3dbaS0xXSAqIFBCKSAlIE1PRDsKICAgIGNpbiA+PiBzMTsgY2luID4+IHMyOwoJaW50IGwxID0gczEuc2l6ZSgpLCBsMiA9IHMyLnNpemUoKTsKICAgIGgxWzBdID0gczFbMF07CiAgICAvL2NvdXQgPDwgaDFbMF0gPDwgIiAiOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPCBsMTsgKytpKQogICAgewogICAgICAgIGgxW2ldID0gKCgoaDFbaS0xXSAqIFBCKSAlIE1PRCkgKyBzMVtpXSkgJSBNT0Q7CiAgICAgICAgLy9jb3V0IDw8IGgxW2ldIDw8ICIgIiA7CiAgICB9CiAgICAvL2NvdXQgPDwgJ1xuJzsgCiAgICBoMlswXSA9IHMyWzBdOwogICAgLy9jb3V0IDw8IGgyWzBdIDw8ICIgIjsKICAgIGZvciAoaW50IGkgPSAxOyBpIDwgbDI7ICsraSkKICAgIHsKICAgICAgICBoMltpXSA9ICgoKGgyW2ktMV0gKiBQQikgJSBNT0QpICsgczJbaV0pICUgTU9EOwogICAgICAgIC8vY291dCA8PCBoMltpXSA8PCAiICIgOwogICAgfQogICAgLy9jb3V0IDw8ICdcbic7IAogICAgaW50IGFucyA9IDA7CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBsMTsgKytpKQogICAgewogICAgICAgIGlmIChsMSAlIGkgPT0gMCAmJiBsMiAlIGkgPT0gMCkKICAgICAgICB7CiAgICAgICAgICAgIGJvb2wgZmxhZyA9IHRydWU7CiAgICAgICAgICAgIGxsIHRlbXAgPSBoMVtpLTFdOwogICAgICAgICAgICBmb3IgKGludCBqID0gMDsgaiA8IGwxOyBqID0gaiArIGkpCgkJCXsKCQkJCWlmICghaikKCQkJCXsKCQkJCQlpZiAodGVtcCAhPSBoMVtqK2ktMV0pCgkJCQkJCWZsYWcgPSBmYWxzZTsKCQkJCQkKCQkJCX0JCiAgICAgICAgICAgICAgICBlbHNlIGlmICh0ZW1wICE9IChoMVtqK2ktMV0gLSAoKGgxW2otMV0gKiBwcG93W2ldKSAlIE1PRCkpKQogICAgICAgICAgICAgICAgICAgIGZsYWcgPSBmYWxzZTsJCQoJCQl9CQkKICAgICAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBsMjsgaiA9IGogKyBpKQogICAgICAgICAgICB7CgkJCQlpZiAoaSA9PSA0KQoJCQkJCWNvdXQgPDwgKGgyW2oraS0xXSAtICgoaDJbai0xXSAqIHBwb3dbaV0pICUgTU9EKSkgPDwgIiAiIDw8ICJjaGVjayIgPDwgJ1xuJzsKCQkJCWlmICghaikKCQkJCXsKCQkJCQlpZiAodGVtcCAhPSBoMltqK2ktMV0pCgkJCQkJCWZsYWcgPSBmYWxzZTsKCQkJCX0JCiAgICAgICAgICAgICAgICBlbHNlIGlmICh0ZW1wICE9IChoMltqK2ktMV0gLSAoKGgyW2otMV0gKiBwcG93W2ldKSAlIE1PRCkpKQogICAgICAgICAgICAgICAgICAgIGZsYWcgPSBmYWxzZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBhbnMgKz0gZmxhZzsKICAgICAgICB9CiAgICB9CiAgICBjb3V0IDw8IGFuczsKICAgIHJldHVybiAwOwp9