Integer division between a dividend n and a divisor d yields a quotient q and a remainder r. q is the integer which maximizes q ∗ d such that q ∗ d ≤ n and r = n − q ∗ d.
    For any set of integers there is an integer d such that each of the given integers when divided by d leaves the same remainder.

Input
Each line of input contains a sequence of nonzero integer numbers separated by a space. The last number on each line is 0 and this number does not belong to the sequence. There will be at least 2 and no more than 1000 numbers in a sequence; not all numbers occuring in a sequence are equal. The last line of input contains a single 0 and this line should not be processed.
Output
For each line of input, output the largest integer which when divided into each of the input integers leaves the same remainder.
Sample Input
701 1059 1417 2312 0
14 23 17 32 122 0
14 -22 17 -31 -124 0
0
Sample Output
179
3
3

问题链接:UVA10407 Simple division
问题简述:给定若干个整数(这些数不完全相同),求使这些数同余的最大除数。
问题分析:(略)
    先求差值,然后再做GCD运算。
    给出2个解法程序,不用数组存储的解法要好一些。
程序说明:(略)
参考链接:(略)
题记:不使用数组存储才是真功夫。

AC的C++语言程序如下:

/* UVA10407 Simple division */#include <bits/stdc++.h>using namespace std;int main()
{int a1, a;while(~scanf("%d", &a1) && a1) {int g = 0;while(scanf("%d", &a) == 1 && a) {int d = a - a1;if(d) {if(g) g = __gcd(g, d); else g = d;}a1 = a;}printf("%d\n", abs(g));}return 0;
}

AC的C++语言程序如下:

/* UVA10407 Simple division */#include <bits/stdc++.h>using namespace std;const int N = 1000;
int d[N];int main()
{int a1, a, cnt, k;while(~scanf("%d", &a1) && a1) {for(cnt = 0; scanf("%d", &a) == 1 && a; cnt++)d[cnt] = a - a1, a1 = a;for(k = 0; d[k] == 0; k++);int g = d[k++];for(; k < cnt; k++)if(d[k]) g = __gcd(g, d[k]);printf("%d\n", abs(g));}return 0;
}

UVA10407 Simple division【同余+一阶差分】相关推荐

  1. Light oj 1214-Large Division (同余定理)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1214 题意很好懂,同余定理的运用,要是A数被B数整除,那么A%B等于0.而A很大,那我 ...

  2. TYUT-A专题题解(二)

    TYUT-A专题题解(一) TYUT-A专题题解(二) 36暴力枚举 AOJ0008 Sum of 4 Integers[暴力]_海岛Blog-CSDN博客 HDU1407 测试你是否和LTC水平一样 ...

  3. Competitive Programming 3题解

    题目一览: Competitive Programming 3: The New Lower Bound of Programming Contests(1) Competitive Programm ...

  4. 图片中的暖色或冷色滤色片是否会带来更多点击? —机器学习A / B测试

    A/B test on ads is the art of choosing the best advertisement that optimizes your goal (number of cl ...

  5. python 添加数据库表_通过时间表(Python库)简化复杂的计划

    python 添加数据库表 by Maxim Mamaev 马克西姆·马马耶夫(Maxim Mamaev) 通过时间表(Python库)简化复杂的计划 (Make your complex sched ...

  6. 引领性指标与滞后性指标_测量可用性组同步滞后

    引领性指标与滞后性指标 With all of the high-availability (HA) and disaster recovery (DR) features, the database ...

  7. π-Algorithmist分类题目(1)

    原题网站:Algorithmist,http://www.algorithmist.com/index.php/Main_Page π-Algorithmist分类题目(1) Sorting UVAL ...

  8. Oracle数据库基础(还在学java吗?不如来看看oracle)

    文章目录 前言 oracle sql 第一章 Selecting Rows(select语句,数据查询操作) 第二章 Sorting & Limiting Selected Rows(排序和限 ...

  9. 对称加密、非对称加密、DES、AES、RSA、OpenSSL、数字签名、防篡改

    本公众号分享的所有技术仅用于学习交流,请勿用于其他非法活动,如果错漏,欢迎留言指正 <加密与解密>第4版 加解密 安全领域的重要分支和基础设施 互联网重要数据的传输需要加解密 TCP/IP ...

最新文章

  1. python类中方法的执行顺序-python 函数或者类 代码的执行顺序
  2. 用VC和MinGW导出dll的def和lib(a)文件
  3. 12999元!小米MIX FOLD致敬未来尊享礼盒上线:限量100套 想买先抽签
  4. ueditor1.4.3 jsp版在ssh下的配置
  5. 【HTTP】Fiddler(一) - Fiddler简介和使用
  6. 第09课 OpenGL 移动图像
  7. arduino蓝牙通讯代码_Arduino蓝牙模块实现通信
  8. wxParse无法解析strong标签
  9. 微信小程序商城项目实战(第九篇:收货地址管理)
  10. 《虚幻4 VR开发指南》视频教程
  11. Thinkphp6 think-queue redis 执行异步任务
  12. 1090: 哥德巴赫猜测
  13. led流水灯c语言数组程序,LED流水灯程序 一维数组写法
  14. ACM赛后总结2018.09.23
  15. 接口报错500是什么意思_HTTP 500错误是什么意思?
  16. Theil-Sen Median斜率估计和Mann-Kendall趋势分析:以多年NPP数据为例
  17. 【HDU】5197 DZY Loves Orzing 【FFT启发式合并】
  18. 半夜仍在加班的我,知道了老板跟女友都在跑步。
  19. 【Python入门】出发吧
  20. tiny4412 裸机程序 八、重定位到DRAM及LCD实验

热门文章

  1. [笔记] 如何从不同扩展名的数字证书中提取明文信息? *.pem *.der *.crt *.cer *.key之间的区别是什么?...
  2. css字体倾斜角度_css如何实现渐变效果?css背景色渐变与文字渐变效果的实现(代码实例)...
  3. JavaScript——(function(){})()立即执行函数解析
  4. SQL那些事儿(十一)--ODBC,OLE-DB,ADO.NET区别
  5. Discuz3.2开启图片列表显示教程
  6. Java中的List、Set、Map
  7. 在C#中使用自定义消息
  8. go get如何删除_Go语言HTTP请求(req库)
  9. g120xa变频器调试参数_西门子G120XA变频器如何进行快速调试
  10. 【java学习之路】(javaWeb【后端】篇)001.XMLTomcatHttp协议