CF182D.Common Divisors

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with.

String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string "abab" has two divisors — "ab" and "abab".

Now Vasya wants to write a program that calculates the number of common divisors of two strings. Please help him.

瓦西娅最近在学校学习了数的约数概念,并决定将这一概念推广到字符串上,定义字符串的“约数”。他的定义如下:

字符串 aa 是字符串 bb 的约数,当且仅当存在某个正整数 xx,使得将字符串 aa 连续重复 xx 次后,恰好得到字符串 bb。例如,字符串 "abab" 有两个约数:"ab" 和 "abab"。

现在,瓦西娅想编写一个程序,用于计算两个字符串的公共约数的个数。请帮助他完成这一任务。

输入格式

The first input line contains a non-empty string _s_1.

The second input line contains a non-empty string _s_2.

Lengths of strings _s_1 and _s_2 are positive and do not exceed 105. The strings only consist of lowercase Latin letters.

第一行输入包含一个非空字符串 s1s_1。
第二行输入包含一个非空字符串 s2s_2。
字符串 s1s_1 和 s2s_2 的长度均为正整数,且不超过 10510^5。这两个字符串仅由小写拉丁字母组成。

输出格式

Print the number of common divisors of strings _s_1 and _s_2.

输出字符串 s1s_1 和 s2s_2 的公共因子的数量。

输入输出样例

  • 输入#1

    abcdabcd
    abcdabcdabcdabcd

    输出#1

    2
  • 输入#2

    aaa
    aa

    输出#2

    1

说明/提示

In first sample the common divisors are strings "abcd" and "abcdabcd".

In the second sample the common divisor is a single string "a". String "aa" isn't included in the answer as it isn't a divisor of string "aaa".

在第一个样例中,公共因子字符串为 “abcd” 和 “abcdabcd”。

在第二个样例中,公共因子字符串仅有一个:“a”。字符串 “aa” 不在答案中,因为它不是字符串 “aaa” 的因子。

输入解题思路,AI测评打分。不知道怎么写?

首页