CF1202F.You Are Given Some Letters...

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given aa uppercase Latin letters 'A' and bb letters 'B'.

The period of the string is the smallest such positive integer kk that si=si mod ks_i = s_{i~mod~k} (00-indexed) for each ii. Note that this implies that kk won't always divide a+b=∣s∣a+b = |s|.

For example, the period of string "ABAABAA" is 33, the period of "AAAA" is 11, and the period of "AABBB" is 55.

Find the number of different periods over all possible strings with aa letters 'A' and bb letters 'B'.

给你 aa 个大写拉丁字母 'A' 和 bb 个字母 'B'。

字符串的周期是指满足对每个 ii 均有 si=si mod ks_i = s_{i~mod~k}(下标从 00 开始)的最小正整数 kk。注意,这并不意味着 kk 总是整除 a+b=∣s∣a+b = |s|。

例如,字符串 "ABAABAA" 的周期为 33,"AAAA" 的周期为 11,而 "AABBB" 的周期为 55。

求在所有由 aa 个 'A' 和 bb 个 'B' 构成的字符串中,不同周期的个数。

输入格式

The first line contains two integers aa and bb (1≤a,b≤1091 \le a, b \le 10^9) — the number of letters 'A' and 'B', respectively.

第一行包含两个整数 aa 和 bb(1≤a,b≤1091 \le a, b \le 10^9),分别表示字母 'A' 和 'B' 的数量。

输出格式

Print the number of different periods over all possible strings with aa letters 'A' and bb letters 'B'.

输出所有由 aa 个字母 'A' 和 bb 个字母 'B' 构成的字符串中,不同周期的数量。

输入输出样例

  • 输入#1

    2 4

    输出#1

    4
  • 输入#2

    5 3

    输出#2

    5

说明/提示

All the possible periods for the first example:

  • 33 "BBABBA"
  • 44 "BBAABB"
  • 55 "BBBAAB"
  • 66 "AABBBB"

All the possible periods for the second example:

  • 33 "BAABAABA"
  • 55 "BAABABAA"
  • 66 "BABAAABA"
  • 77 "BAABAAAB"
  • 88 "AAAAABBB"

Note that these are not the only possible strings for the given periods.

第一个示例的所有可能周期:

  • 33 "BBABBA"
  • 44 "BBAABB"
  • 55 "BBBAAB"
  • 66 "AABBBB"

第二个示例的所有可能周期:

  • 33 "BAABAABA"
  • 55 "BAABABAA"
  • 66 "BABAAABA"
  • 77 "BAABAAAB"
  • 88 "AAAAABBB"

注意:对于给定的周期,这些并非唯一可能的字符串。

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

首页