Problem Statement
There are N monsters, numbered 1,2,…,N.
Initially, the health of Monster i is Ai.
Below, a monster with at least 1 health is called alive.
Until there is only one alive monster, the following is repeated:
A random alive monster attacks another random alive monster.
As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking.
Find the minimum possible final health of the last monster alive.
Constraints
All values in input are integers.
2≤N≤105
1≤Ai≤109
Input
Input is given from Standard Input in the following format:
N
A1 A2 … AN
Output
Print the minimum possible final health of the last monster alive.
Sample Input 1
4
2 10 8 40
Sample Output 1
2
When only the first monster keeps on attacking, the final health of the last monster will be 2, which is minimum.
Sample Input 2
4
5 13 8 1000000000
Sample Output 2
1
Sample Input 3
3
1000000000 1000000000 1000000000
Sample Output 3
1000000000
思路:这道题就是找最后可以剩下的最小的生命值,由于攻击者在攻击时并不减少血量,所以所剩下最小的一定小于等于初始生命值最小的怪兽,当一个怪兽生命值是另一个怪兽生命值的倍数的时候,那么另一个怪兽就可以完全被生命值小的那个怪兽消灭掉,如果不是整数倍,也可以辗转相减(???)最后得出生下的生命值最小的怪兽。
就是求所有数的最大公约数。。。
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int mod=998244353;
int a[1000010];
int main()
{
int n;
cin >>n;
int x;
cin >>x;
int sum=x;
for(int i=1;i<n;i++)
{
cin >>x;
sum=__gcd(sum,x);
}
cout <<sum<<endl;
return 0;
}