A12833 | You Are Given Some Letters...
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given $a$ uppercase Latin letters 'A' and $b$ letters 'B'.
The period of the string is the smallest such positive integer $k$ that $s_i = s_{i~mod~k}$ ( $0$ -indexed) for each $i$ . Note that this implies that $k$ won't always divide $a+b = |s|$ .
For example, the period of string "ABAABAA" is $3$ , the period of "AAAA" is $1$ , and the period of "AABBB" is $5$ .
Find the number of different periods over all possible strings with $a$ letters 'A' and $b$ letters 'B'.
The period of the string is the smallest such positive integer $k$ that $s_i = s_{i~mod~k}$ ( $0$ -indexed) for each $i$ . Note that this implies that $k$ won't always divide $a+b = |s|$ .
For example, the period of string "ABAABAA" is $3$ , the period of "AAAA" is $1$ , and the period of "AABBB" is $5$ .
Find the number of different periods over all possible strings with $a$ letters 'A' and $b$ letters 'B'.
输入格式
The first line contains two integers $a$ and $b$ ( $1 \le a, b \le 10^9$ ) — the number of letters 'A' and 'B', respectively.
输出格式
Print the number of different periods over all possible strings with $a$ letters 'A' and $b$ letters 'B'.
输入输出样例
输入 #1
2 4
输出 #1
4
输入 #2
5 3
输出 #2
5
All the possible periods for the first example:
- $3$ "BBABBA"
- $4$ "BBAABB"
- $5$ "BBBAAB"
- $6$ "AABBBB"
All the possible periods for the second example:
- $3$ "BAABAABA"
- $5$ "BAABABAA"
- $6$ "BABAAABA"
- $7$ "BAABAAAB"
- $8$ "AAAAABBB"
Note that these are not the only possible strings for the given periods.
- $3$ "BBABBA"
- $4$ "BBAABB"
- $5$ "BBBAAB"
- $6$ "AABBBB"
All the possible periods for the second example:
- $3$ "BAABAABA"
- $5$ "BAABABAA"
- $6$ "BABAAABA"
- $7$ "BAABAAAB"
- $8$ "AAAAABBB"
Note that these are not the only possible strings for the given periods.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted