Common Divisors CodeForces

题意:

给你n个数,让你找出来公因子有多少个。公因子:对于这n个数,都能被这个公因子整除

题解:

只需要找出来这n个数的最大公因子x,然后找出来有多少不同数能把x给整。(因为我们可以保证x可以把这n个数整除,又因为x是最大公因数,那么能把x整除的数肯定也可以把这n个数整除)

代码:

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<iostream>
 4 #include<algorithm>
 5 #include<queue>
 6 #include<map>
 7 #include<vector>
 8 #include<math.h>
 9 #define mem(a,x) memset(a,x,sizeof(a))
10 using namespace std;
11 typedef long long ll;
12 const int maxn=1005;
13 const int mod=26;
14 const int INF=0x3f3f3f3f;
15 const int Times = 10;
16 const int N = 5500;
17 ll gcd(ll a,ll b)
18 {
19     return b?gcd(b,a%b):a;
20 }
21 ll v[400005];
22 int main()
23 {
24     ll n;
25     scanf("%I64d",&n);
26     ll ans,v;
27     scanf("%I64d",&ans);
28     n--;
29     while(n--)
30     {
31         scanf("%I64d",&v);
32         ans=gcd(ans,v);
33     }
34     ll s=0;
35     for(ll i=1; i<=sqrt(ans); i++)
36     {
37         if(ans%i==0)
38         {
39             if(ans/i==i)
40             {
41                 s--;
42             }
43             s+=2;
44         }
45     }
46     printf("%I64d
",s);
47     return 0;
48 }
原文地址:https://www.cnblogs.com/kongbursi-2292702937/p/12678046.html