CF Infinite Sequence

本文探讨了一个数学问题,即如何判断一个无限序列中是否存在特定整数。该序列的第一个元素已知,且任意两个相邻元素间的差值固定。文章提供了一种算法解决方案,并附带了源代码。

Infinite Sequence

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status

Description

描述

Vasyalikes everything infinite.  Now he isstudying the properties of a sequence s, such that its first element is equalto a (s1 = a), and the difference between any two neighbouring elements isequal to c (si - si - 1 = c).  Inparticular, Vasya wonders if his favourite integer b appears in this sequence,that is, there exists a positive integer i, such that si = b.  Of course, you are the person he asks for ahelp.

Vasya喜欢一切无限。现在,他正在研究一个序列s的属性,这样它的第一个元素等于a ,并且和任何两个相邻元素之间的区别=c(si - si - 1 = c)。特别是Vasya感兴趣他最喜欢整数b出现在这个序列,也就是说,存在一个正整数,这样如果=b。当然,你是他要求帮助的人。

 

 

Input

输入

Thefirst line of the input contain three integers a, b and c ( - 109  a, b, c  109)the first element of the sequence, Vasya's favorite number and the differencebetween any two neighbouring elements of the sequence, respectively.

输入的第一行包含三个整数a,bc(-109≤a,b,c≤109)-第一个元素的序列,Vasya最喜欢的数量和序列的任何两个相邻元素之间的区别,分别。

 

 

Output

输出

Ifb appears in the sequence s print "YES" (without quotes), otherwiseprint "NO" (without quotes).

如果b出现在序列s打印“YES”(没有引号),否则打印”(没有引号)

Sample Input

Input

17 3

Output

YES

Input

1010 0

Output

YES

Input

1-4 5

Output

NO

Input

060 50

Output

NO

 

题意:就是给定三个数a,b,c。判断能不能满足a+n*c==b

 

思路:1,考虑特殊情况

2,利用(b-a)/a的整型与浮点型答案比较,相等就是YES。另外 n >=0



/*=============================AC情况===============================*/
/*题目网址:   */
/*时间: */
/*心得:  */

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define G 100

int main() {
	int sign1;
	double sign2,a,b,c;
	while(scanf("%lf%lf%lf",&a,&b,&c)!=EOF) {
		if(c==0) {
			if(a==b)
				printf("YES\n");
			else
				printf("NO\n");
		} else {
			sign1=(int)((b-a)/c);
			sign2=((b-a)/c);
			//printf("%d %lf",sign1,sign2);
			if(sign1>=0&&sign1==sign2)
				printf("YES\n");
			else
				printf("NO\n");
		}
	}
	return 0;
}

/*********************************测试数据*********************************


**************************************************************************/



在编程和技术的语境中,“infinite”(无限)通常指的是循环、序列、数据结构或资源使用上的无限制特性。以下是与“infinite”相关的几个常见概念和实现方法: --- **1. 无限循环 (Infinite Loop)** 无限循环是指程序中的一个控制结构,它会持续执行直到被外部中断。这种循环可能用于服务器监听、任务调度或实时系统中。 ```python while True: print("This is an infinite loop") ``` 需要注意的是,无限循环如果不加以控制可能会导致性能问题或资源耗尽。 --- **2. 无限序列 (Infinite Sequence)** 在函数式编程语言(如 Haskell)中,可以生成无限序列。Python 中也可以通过生成器实现类似功能。例如,生成无限递增的整数序列: ```python def infinite_sequence(): num = 0 while True: yield num num += 1 gen = infinite_sequence() for _ in range(5): print(next(gen)) # 输出前五个数字 ``` --- **3. 无限滚动 (Infinite Scrolling)** 在前端开发中,“infinite scrolling” 是一种用户体验设计模式,允许用户在页面上连续加载内容而无需分页。这通常通过 JavaScript 和 AJAX 技术实现。例如: ```javascript window.addEventListener('scroll', () => { if (window.innerHeight + window.scrollY >= document.body.offsetHeight) { loadMoreContent(); // 调用加载更多内容的函数 } }); ``` --- **4. 无限资源分配 (Infinite Resource Allocation)** 在云计算和分布式系统中,“infinite” 可能指代虚拟化的资源池,例如 CPU、内存或存储空间。实际上,这些资源并非真正无限,但通过动态扩展和负载均衡技术,可以为用户提供“无限”的体验。 --- **5. 数学中的无限 (Infinity in Mathematics)** 在编程中,某些语言支持表示数学上的无穷大。例如,在 Python 中可以这样定义: ```python positive_infinity = float('inf') negative_infinity = float('-inf') print(positive_infinity > 1e308) # 输出 True ``` --- **6. 算法中的无限 (Infinity in Algorithms)** 在算法设计中,尤其是图论和最短路径问题中,“无限”常用来表示不可达的距离。例如,在 Dijkstra 算法中初始化距离矩阵时: ```python import math distances = [math.inf] * n # 初始化所有节点距离为无穷大 distances[start_node] = 0 # 起点距离为 0 ``` ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值