[Time Gate]
https://www.luogu.org/problemnew/show/P4549
[Problem-solving ideas]
Greatest common divisor of number theory + + indeterminate equation
Shu Pei content and brief proof of Theorem
ax + by = c Sufficient Conditions (xy is any integer) holds c is a multiple of gcd (a, b) of
Set S = gcd (A, B) , apparently S | A, and s|b
And because x, y∈Z *
So s|ax, s|by
Prior to making formula is clearly established, it must meet c is a and b multiple of the Convention
And because x and y are positive integers
Therefore c must be a, b, the common denominator
Therefore, the proof of the theorem was established
The same number can be more
【code】
1 #include <cstdio> 2 #include <iostream> 3 #include <algorithm> 4 using namespace std; 5 int n,k,ans; 6 inline int gcd(int a,int b){ 7 if(b==0)return a; 8 return gcd(b,a%b); 9 } 10 int main(){ 11 //freopen("4549.in","r",stdin); 12 //freopen("4549.out","w",stdout); 13 scanf("%d",&n); 14 for(register int i=1;i<=n;i++){ 15 scanf("%d",&k); 16 if(k<0)k*=(-1); 17 ans= gcd(ans,k); 18 } 19 printf("%d\n",ans); 20 return 0; 21 }