CF1146D.Frog Jumping
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 ∑i=0mf(i). That is, find the sum of all f(i) for i from 0 to m.
一只青蛙初始位于数轴上的位置 0。该青蛙有两个正整数 a 和 b。从位置 k 出发,它可跳至位置 k+a 或 k−b。
定义 f(x) 为:当青蛙的跳跃始终不超出区间 [0,x](即不允许落在该区间外的整数上)时,它所能到达的不同整数的个数。注意,青蛙无需在一次行程中访问所有这些整数;只要存在某种方式(从 0 出发)使其能够到达某个整数,该整数即被计入。
给定一个整数 m,求 ∑i=0mf(i)。即,求所有 f(i)(其中 i 从 0 到 m)的和。
输入格式
The first line contains three integers m,a,b (1≤m≤109,1≤a,b≤105).
第一行包含三个整数 m,a,b(1≤m≤109, 1≤a,b≤105)。
输出格式
Print a single integer, the desired sum.
输出一个整数,即所求的和。
输入输出样例
输入#1
7 5 3
输出#1
19
输入#2
1000000000 1 2019
输出#2
500000001500000001
输入#3
100 100000 1
输出#3
101
输入#4
6 4 5
输出#4
10
说明/提示
In the first example, we must find f(0)+f(1)+…+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 ∑i=0109i+1.
In the third example, the frog can't make any jumps in any case.
在第一个例子中,我们需要计算 f(0)+f(1)+…+f(7)。我们有 f(0)=1,f(1)=1,f(2)=1,f(3)=1,f(4)=1,f(5)=3,f(6)=3,f(7)=8。这些值的和为 19。
在第二个例子中,我们有 f(i)=i+1,因此需要计算 ∑i=0109i+1。
在第三个例子中,青蛙在任何情况下都无法进行跳跃。
输入解题思路,AI测评打分。不知道怎么写?