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. Linux学习 - 树莓派4b的U-Boot的初识

    Linux学习 - 树莓派4b的U-Boot的初识 初识U-Boot 学习书籍:<[正点原子]I.MX6U嵌入式Linux驱动开发指南V1.5.1> 章节:第三十章 学习内容: 书中介绍u ...

  2. 【PS】证件照修改尺寸

    证件照同时修改尺寸.分辨率.像素 2019-07-14  12:56:25  by冲冲 1. 需求 实现证件照自由切换一寸.小一寸.大一寸.二寸. 2. 步骤 ① 裁剪工具 -- 原始比例 -- 存储 ...

  3. GPG 使用指南

    加密与签名 在传输信息时,会面临两个典型的问题: 如何保证发出的消息,只能被预期的接收人获取? 如何保证收到的消息,确实由预期的发送人发出? 这两个问题不难理解.例如发送的邮件可能会被监听,诈骗分子可 ...

  4. DP+单调队列详解+题目

    介绍: 单调队列优化的原理   先回顾单调队列的概念,它有以下特征:   (1)单调队列的实现.用双端队列实现,队头和队尾都能插入和弹出.手写双端队列很简单.   (2)单调队列的单调性.队列内的元素 ...

  5. 什么是CLI、GUI

    就是命令行界面command-line interface,也有人称之为字符用户界面(CUI). 通常认为,命令行界面(CLI)没有图形用户界面(GUI)那么方便用户操作. 因为,命令行界面的软件通常 ...

  6. 7.1 k8s使用configmapg 给pod内的程序提供配置文件

    ConfigMap 是一种 API 对象,用来将非机密性的数据保存到键值对中.使用时, Pods 可以将其用作环境变量.命令行参数或者存储卷中的配置文件. 以下以nginx镜像提供配置文件为例镜像演示 ...

  7. 洛谷 P4931 - [MtOI2018]情侣?给我烧了!(加强版)(组合数学)

    洛谷题面传送门 A 了这道题+发这篇题解,就当过了这个七夕节吧 奇怪的过节方式又增加了 首先看到此题第一眼我们可以想到二项式反演,不过这个 \(T\) 组数据加上 \(5\times 10^6\) 的 ...

  8. [linux] 非root安装Python2及其模块

    需求 系统自带的python2版本太低,且没有想要的模块,非root用户无法安装.有些模块是python2写的,无法用python3,所以自己下载一个高版本的python2,可以自由下载模块. 实现 ...

  9. 汽车C2M模式综述

  10. 简易kmeans-c++版本

    typedef double dtype; 主要接口: void Kmeans(const vector<vector<dtype> > &d,int k,string ...