链接:

https://codeforces.com/contest/1216/problem/D

题意:

There were n types of swords in the theater basement which had been used during the plays. Moreover there were exactly x swords of each type. y people have broken into the theater basement and each of them has taken exactly z swords of some single type. Note that different people might have taken different types of swords. Note that the values x,y and z are unknown for you.

The next morning the director of the theater discovers the loss. He counts all swords — exactly ai swords of the i-th type are left untouched.

The director has no clue about the initial number of swords of each type in the basement, the number of people who have broken into the basement and how many swords each of them have taken.

For example, if n=3, a=[3,12,6] then one of the possible situations is x=12, y=5 and z=3. Then the first three people took swords of the first type and the other two people took swords of the third type. Note that you don't know values x,y and z beforehand but know values of n and a.

Thus he seeks for your help. Determine the minimum number of people y, which could have broken into the theater basement, and the number of swords z each of them has taken.

思路:

将最大值设为x, 求出x-每个值的gcd, 就是每个人能拿的最大值.

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 2e5+10; LL a[MAXN];
int n; int main()
{
cin >> n;
LL gcd = 0, mmax = 0;
for (int i = 1;i <= n;i++)
cin >> a[i], mmax = max(mmax, a[i]);
for (int i = 1;i <= n;i++)
gcd = __gcd(gcd, mmax-a[i]);
LL num = 0;
for (int i = 1;i <= n;i++)
num += (mmax-a[i])/gcd;
cout << num << ' ' << gcd << endl; return 0;
}

最新文章

  1. [Java面试八]Hibernate总结以及在面试中的一些问题.
  2. IOS中取乱序数据最大值、最小值方法
  3. Retina视网膜屏中CSS3边框图片像素虚边的问题
  4. C#往线程里传递参数
  5. 常用CSS3效果:用text-shadow做CSS3 文字描边
  6. Oracle 中 for update 和 for update nowait 的区别
  7. SQL DCL数据控制语言,用来定义訪问权限和安全级别;
  8. fastcgi重启
  9. 201521123021《Java程序设计》第1周学习总结
  10. LeetCode之“动态规划”:Distinct Subsequences
  11. 3.CNN-卷积神经网络推导
  12. SQL Server 关于 Table 字典数据的查询SQL
  13. hdu1201,hdu6252差分约束系统
  14. openjudge noi 鸡尾酒疗法
  15. andorid 列表视图 ListView 之BaseAdapter
  16. ASP.NET Core CMS管理后台
  17. TCP连接详解
  18. 洛谷P2114 [NOI2014]起床困难综合症
  19. HDUOJ---1195Open the Lock
  20. Spring学习笔记--声明一个简单的Bean

热门文章

  1. 如何获得select被选中option的value和text和......
  2. AtCoder M-SOLUTIONS 2019 Task E. Product of Arithmetic Progression
  3. Netty的学习
  4. SpingMVC使用小结
  5. selenium登录4399
  6. Beautifulsoup模块基础用法详解
  7. react的状态管理
  8. Foo Fighters CodeForces - 1148F
  9. NIPS2018最佳论文解读:Neural Ordinary Differential Equations
  10. 如何理解归一化(Normalization)对于神经网络(深度学习)的帮助?