CF675A Infinite Sequence 题解
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 题解的更多相关文章
- Educational Codeforces Round 7 A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...
- codeforces 622A Infinite Sequence
A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 【arc071f】Infinite Sequence(动态规划)
[arc071f]Infinite Sequence(动态规划) 题面 atcoder 洛谷 题解 不难发现如果两个不为\(1\)的数连在一起,那么后面所有数都必须相等. 设\(f[i]\)表示\([ ...
- Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...
- CodeForces 622 A.Infinite Sequence
A.Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...
- codeforces 675A A. Infinite Sequence(水题)
题目链接: A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input st ...
- 【CF486E】LIS of Sequence题解
[CF486E]LIS of Sequence题解 题目链接 题意: 给你一个长度为n的序列a1,a2,...,an,你需要把这n个元素分成三类:1,2,3: 1:所有的最长上升子序列都不包含这个元素 ...
- codeforces 622A A. Infinite Sequence (二分)
A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...
- A - Infinite Sequence
Problem description Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, ...
随机推荐
- Error occurred during initialization of VM Could not reserve enough space fo
通过es的elasticsearch.bat 启动.发现错误:Error occurred during initialization of VM Could not reserve enough s ...
- (前端)面试300问之(2)CSS元素居中【水平、垂直、2者同时居中】
一 仅水平居中 1 行内元素 1)给父元素添加 text-align:center 即可 <div class="parent"> <span class=&qu ...
- Jmeter BlazeMeter实现web录制
1. BlazeMeter安装和注册 BlazeMeter是一款与Apache JMeter兼容的chrome插件,采用BlazeMeter可以方便的进行流量录制和脚本生成,作为接口测试脚本编写的 ...
- Codeforces 559E - Gerald and Path(dp)
题面传送门 真·难度 *3000 的 D1E hb 跟我们说"做不出来不太应该". 首先我们将所有线段按 \(a_i\) 从小到大排序,一个很显然的想法是 \(dp_{i,j,d} ...
- R语言实战-Part 2笔记
R 语言实战(第二版) part 2 基本方法 -------------第6章 基本图形------------------ #1.条形图 #一般是类别型(离散)变量 library(vcd) he ...
- Linux openssl 升级、降级
Linux openssl 升级.降级 最近遇到一些朋友使用微信退款,报openssl版本为问题,需要对openssl进行降级. 现在环境的openssl版本如下: root@c215a2b695ef ...
- 学习Java的第十八天
一.今日收获 1.java完全学习手册第三章算法的3.1比较值 2.看哔哩哔哩上的教学视频 二.今日问题 1.在第一个最大值程序运行时经常报错. 2.哔哩哔哩教学视频的一些术语不太理解,还需要了解 三 ...
- day06 HTTP协议
day06 HTTP协议 HTTP协议 什么是http? HTTP 全称:Hyper Text Transfer Protocol 中文名:超文本传输协议 是一种按照URL指示,将超文本文档从一台主机 ...
- day11 函数
day11 函数 一.函数基础 """ 1 什么是函数 函数是盛放代码的容器:把实现某一功能的代码放到一个函数内就制造一个工具 2 为何要用函数 没有用函数之前程序的问题 ...
- 单体内置对象 Global 和 Math
单体内置对象 Global 和 Math 在所有代码执行前,作用域中就已经存在两个内置对象:Global(全局)和Math.在大多数ES实现中都不能直接访问Global对象.不过,WEB浏览器实现了承 ...