Forethought Future Cup - Elimination Round
D
Frog Jumping
Codeforces
2100
原题
← CE →
翻译中…

A frog is initially at position $0$ on the number line. The frog has two positive integers $a$ and $b$. From a position $k$, it can either jump to position $k+a$ or $k-b$.

翻译中…

Let $f(x)$ be the number of distinct integers the frog can reach if it never jumps on an integer outside the interval $[0, x]$. The frog doesn't need to visit all these integers in one trip, that is, an integer is counted if the frog can somehow reach it if it starts from $0$.

翻译中…

Given an integer $m$, find $\sum_{i=0}^{m} f(i)$. That is, find the sum of all $f(i)$ for $i$ from $0$ to $m$.

翻译中…

Input

翻译中…

The first line contains three integers $m, a, b$ ($1 \leq m \leq 10^9, 1 \leq a,b \leq 10^5$).

翻译中…

Output

翻译中…

Print a single integer, the desired sum.

翻译中…

Note

翻译中…

In the first example, we must find $f(0)+f(1)+\ldots+f(7)$. We have $f(0) = 1, f(1) = 1, f(2) = 1, f(3) = 1, f(4) = 1, f(5) = 3, f(6) = 3, f(7) = 8$. The sum of these values is $19$.

翻译中…

In the second example, we have $f(i) = i+1$, so we want to find $\sum_{i=0}^{10^9} i+1$.

翻译中…

In the third example, the frog can't make any jumps in any case.

翻译中…

样例

Input #1
7 5 3
Output #1
19
InputCopy OutputCopy
Input #2
1000000000 1 2019
Output #2
500000001500000001
InputCopy OutputCopy
Input #3
100 100000 1
Output #3
101
InputCopy OutputCopy
Input #4
6 4 5
Output #4
10
InputCopy OutputCopy
题目信息
题号
1146D
时间限制
2 s
内存限制
256 MB
标签
DFS 及类似
数学
数论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。