Content

给定三个整数 \(a,b,c\),问你 \(b\) 是否在以 \(a\) 为首项,公差为 \(c\) 的等差数列中。

数据范围:\(-10^9\leqslant a,b,c\leqslant 10^9\)。

Solution

给出两个定理:设 \(x_n\) 在以 \(x_1\) 为首项,公差为 \(d(d\neq 0)\) 的等差数列中,那么就有:

\(1.\) \(d\mid (x_n-x_1)\)。

\(2.\) \(\dfrac{x_n-x_1}{d}\geqslant 0\)。

证明 \(1\):众所周知,一个首项为 \(x_1\),公差为 \(d\) 的等差数列的第 \(n\) 项 \(x_n\) 为 \(x_1+(n-1)d\),那么必然就有 \(\dfrac{x_n-x_1}{d}=n-1\) 为整数,所以就有 \(d\mid (x_n-x_1)\)。

证明 \(2\):由证明 \(1\) 我们可以知道,\(\dfrac{x_n-x_1}{d}=n-1\)。又因为 \(n\geqslant 1\),所以 \(n-1\geqslant 0\),通过等量代换就有 \(\dfrac{x_n-x_1}{d}\geqslant 0\)。

证毕。

但问题是,数据范围没有说公差 \(c\) 为 \(0\)!怎么办?

其实很简单,当公差 \(c\) 为 \(0\) 的时候,那么很显然,等差数列里面的每一项都相等,所以我们只需要判断是否有 \(a=b\) 即可。

Code

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <iostream>
using namespace std; int a, b, c; int main() {
scanf("%d%d%d", &a, &b, &c);
if(!c) {
if(a == b) printf("YES");
else printf("NO");
}
else if(((b - a) / c >= 0 && (b - a) / c * c == b - a)) printf("YES");//这里判断是否是整数
else printf("NO");
return 0;
}

CF675A Infinite Sequence 题解的更多相关文章

  1. Educational Codeforces Round 7 A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...

  2. codeforces 622A Infinite Sequence

    A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. 【arc071f】Infinite Sequence(动态规划)

    [arc071f]Infinite Sequence(动态规划) 题面 atcoder 洛谷 题解 不难发现如果两个不为\(1\)的数连在一起,那么后面所有数都必须相等. 设\(f[i]\)表示\([ ...

  4. Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...

  5. CodeForces 622 A.Infinite Sequence

    A.Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. codeforces 675A A. Infinite Sequence(水题)

    题目链接: A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input st ...

  7. 【CF486E】LIS of Sequence题解

    [CF486E]LIS of Sequence题解 题目链接 题意: 给你一个长度为n的序列a1,a2,...,an,你需要把这n个元素分成三类:1,2,3: 1:所有的最长上升子序列都不包含这个元素 ...

  8. codeforces 622A A. Infinite Sequence (二分)

    A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. A - Infinite Sequence

    Problem description Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2,  ...

随机推荐

  1. SpringCloud升级之路2020.0.x版-41. SpringCloudGateway 基本流程讲解(2)

    本系列代码地址:https://github.com/JoJoTec/spring-cloud-parent 我们继续分析上一节提到的 WebHandler,经过将请求封装成 ServerWebExc ...

  2. 日志审计功能-appent多个日志

    public static void main(String[] args) { Jedis jedis = new Jedis("127.0.0.1"); jedis.setnx ...

  3. 面渣逆袭:HashMap追魂二十三问

    大家好,我是老三. HashMap作为我们熟悉的一种集合,可以说是面试必考题.简单的使用,再到原理.数据结构,还可以延伸到并发,可以说,就一个HashMap,能聊半个小时. 1.能说一下HashMap ...

  4. [省选联考 2021 A 卷] 矩阵游戏

    很巧妙的一个构造. 我是没有想到的. 自己的思维能力可能还是不足. 考虑先满足\(b\)对\(a\)的限制,把\(a\)的第一行和第一列设\(0\),推出这个\(a\). 接下来考虑对这个\(a\), ...

  5. Codeforces 1503E - 2-Coloring(组合数学)

    Codeforces 题目传送门 & 洛谷题目传送门 考虑什么样的 2-染色方式是符合题目要求的,首先蓝.黄颜色所形成的连通块个数必须 \(\le 2\),否则一定不合法,而显然如果两种颜色连 ...

  6. DTOJ 3987: 数学课

    题目描述 wzy又来上数学课了-- 虽然他很菜,但是数学还是懂一丢丢的.老师出了一道题,给定一个包含$n$个元素的集合$P=1,2,3--n$求有多少集合$A \subseteq P$,满足$x \i ...

  7. jsp的动态包含和静态包含

    jsp的动态包含和静态包含 例如:提取一个公共的页面(top.jsp)到/WEB-INF/jsp/common/目录下 动态包含: 被包含的页面也会独立编译,生成字节码文件,一般包含页面信息频繁变化的 ...

  8. 学习java的第八天

    一.今日收获 1.学习完全学习手册上2.3转义字符与2.4运算符两节 二.今日难题 1.没有什么难理解的问题 三.明日目标 1.哔哩哔哩教学视频 2.Java学习手册

  9. Vue函数防抖和函数节流

    函数防抖(debounce) 应用场景 登录.发短信等按钮避免用户点击太快,以致于发送了多次请求,需要防抖 调整浏览器窗口大小时,resize 次数过于频繁,造成计算过多,此时需要一次到位,就用到了防 ...

  10. [C++] vptr, where are you?

    Search(c++在线运行). 有的网站很慢--不是下面的程序有问题. #include <string.h> #include <stdio.h> #include < ...