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. synchronized的一些理解

    1. 两个普通的synchronized package ThreadTest; import java.util.concurrent.TimeUnit; public class ThreadTe ...

  2. 【Azure 应用服务】App Service 无法连接到Azure MySQL服务,报错:com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

    问题描述 App Service使用jdbc连接MySQL服务,出现大量的  Communications link failure: com.mysql.cj.jdbc.exceptions.Com ...

  3. .NET 开源免费图表组件库,Winform,WPF 通用

    大家好, 我是等天黑, 今天给大家介绍一个功能完善, 性能强悍的图表组件库 ScottPlot, 当我第一次在 github 上看到这个库, 我看不懂,但我大受震撼, 这么好的项目当然要分享出来了. ...

  4. sb 错误

    数组开小.很容易 \(2 \times 10^5\) 或 \(10^6\) 就开成 \(10^5\),或者各种变量的数据范围混用,\(m \leq 5\times 10^5\),结果只开到了 \(n\ ...

  5. 洛谷 P7718 -「EZEC-10」Equalization(差分转化+状压 dp)

    洛谷题面传送门 一道挺有意思的题,现场切掉还是挺有成就感的. 首先看到区间操作我们可以想到差分转换,将区间操作转化为差分序列上的一个或两个单点操作,具体来说我们设 \(b_i=a_{i+1}-a_i\ ...

  6. Codeforces 497E - Subsequences Return(矩阵乘法)

    Codeforces 题目传送门 & 洛谷题目传送门 一道还算不错的矩乘 tea 罢,不过做过类似的题应该就比较套路了-- 首先考虑对于一个固定的序列 \(\{a\}\) 怎样求其本质不同的序 ...

  7. 认识Influxdb时序数据库及Influxdb基础命令操作

    认识Influxdb时序数据库及Influxdb基础命令操作 一.什么是Influxdb,什么又是时序数据库 Influxdb是一个用于存储时间序列,事件和指标的开源数据库,由Go语言编写而成,无需外 ...

  8. perl 获取目录信息

    1 #!/usr/bin/perl -w 2 use strict; 3 use FindBin qw($Bin $Script); 4 5 my $rp=$Bin; 6 print "th ...

  9. 关于蓝牙Mesh您必须知道的七件事

    蓝牙技术联盟于7月19日正式宣布,蓝牙(Bluetooth)技术开始全面支持Mesh网状网络.全新的Mesh功能提供设备间多对多传输,并特别提高构建大范围网络覆盖的通信能力,适用于楼宇自动化.无线传感 ...

  10. Vue相关,vue父子组件生命周期执行顺序。

    一.实例代码 父组件: <template> <div id="parent"> <child></child> </div& ...