http://codeforces.com/problemset/problem/389/A
最大公因数新求法,get
把除法变成加法。
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <algorithm> 4 using namespace std; 5 int main() 6 { 7 int gcd(int,int); 8 int n; 9 int a; 10 scanf("%d",&n); 11 scanf("%d",&a); 12 int gong_yin_shu=a; 13 for(int i=1;i<n;i++){ 14 scanf("%d",&a); 15 gong_yin_shu=gcd(gong_yin_shu,a); 16 } 17 printf("%d\n",gong_yin_shu*n); 18 return 0; 19 } 20 int gcd(int a,int b) 21 { 22 while(1){ 23 a=a%b; 24 if(a==0) return b; 25 b=b%a; 26 if(b==0) return a; 27 } 28 }