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, ...
随机推荐
- 『学了就忘』Linux用户管理 — 52、用户组管理相关命令
目录 1.添加用户组 2.删除用户组 3.把用户添加进组或从组中删除 4.有效组(了解) 1.添加用户组 添加用户组的命令是groupadd. 命令格式如下: [root@localhost ~]# ...
- 记一次 android 线上 oom 问题
背景 公司的主打产品是一款跨平台的 App,我的部门负责为它提供底层的 sdk 用于数据传输,我负责的是 Adnroid 端的 sdk 开发. sdk 并不直接加载在 App 主进程,而是隔离在一个单 ...
- No 'Access-Control-Allow-Origin' header: 跨域问题踩坑记录
前言 前两周在服务器上部署一个系统时,遇到了跨域问题,这也不是第一次遇到跨域问题了,本来以为解决起来会很顺利,没想到解决过程中遇到了很多坑,所以觉得有必要写一篇博客记录一下这个坑. 问题产生原因 本来 ...
- 快来使用Portainer让测试环境搭建飞起来吧
Portainer是Docker的图形化管理工具,提供状态显示面板.应用模板快速部署.容器镜像网络数据卷的基本操作(包括上传下载镜像,创建容器等操作).事件日志显示.容器控制台操作.Swarm集群和服 ...
- 【树莓派】Python开发工控机急停设计
背景 我们在一些工业产品中使用树莓派替代了PLC和上位机,并借助树莓派的算力将AI和机器视觉引入工业领域. 以前的产品都不存在动作机构,仅仅将结果输出到指示灯.蜂鸣器或者显示器上,没有安全隐患, 现在 ...
- ABC 210
A 按题意模拟. scanf("%lld%lld%lld%lld",&n,&a,&x,&y); std::cout<<n * x - ( ...
- Codeforces 1290F - Making Shapes(数位 dp)
Codeforces 题面传送门 & 洛谷题面传送门 数位 dp 好题. 首先,由于是凸包,一但向量集合确定,凸包的形态肯定就已经确定了.考虑什么样的向量集合能够组成符合条件的凸包,我们假设第 ...
- 【python】python之list
1.判断list是否为空 方式一: list_temp=[] if len(list_temp): #非空即为真 print('list is not empty') else: print('lis ...
- python3安装,支持openssl,支持采集https
python3安装,支持openssl,支持采集https 坑好多,特别是安装的时候,各种不匹配,服务器默认配置是python2,升级3后,采集的时候用到openssl,花了两天也没搞定各种错误,也许 ...
- 【NCBI教程】资源汇总整理 (转载)
主题 网址 备注 [NCBI教程]资源汇总整理 http://www.omicshare.com/forum/thread-200-1-1.html (出处: OmicShare Forum)