C. Common Divisors
Problem
You are given an array a a a consisting of n n n integers.
Your task is to say the number of such positive integers x x x such that x x x divides each number from the array. In other words, you have to find the number of common divisors of all elements in the array.
For example, if the array a a a will be [ 2 , 4 , 6 , 2 , 10 ] \left[2,4,6,2,10\right] [2,4,6,2,10], then 1 1 1 and 2 2 2 divide each number from the array (so the answer for this test is 2 2 2).
Input
The first line of the input contains one integer n ( 1 ≤ n ≤ 4 × 1 0 5 ) n (1 \leq n \leq 4 \times 10^5) n(1≤n≤4×105) — the number of elements in a a a.
The second line of the input contains n n n integers a 1 , a 2 , … , a n ( 1 ≤ a i ≤ 1 0 12 ) a_1,a_2,…,a_n (1 \leq a_i \leq 10^{12}) a1,a2,…,an(1≤ai≤1012), where a i a_i ai is the i t h i^{th} ith element of a a a.
Output
Print one integer — the number of such positive integers x x x such that x x x divides each number from the given array (in other words, the answer is the number of common divisors of all elements in the array).
Examples
input
5
1 2 3 4 5
output
1
input
6
6 90 12 18 30 18
output
4
想法
这题题意是找出这些树的公共的因子的数目
那么这里很容易想到求这些数的gcd然后求gcd的因子数就是这些数的公共因子数
The Code Of My Program
/*********************
*@Author: ChenShou *
*@Language: C++11 *
*********************/
//#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
#include<functional>
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
#define endl "\n"
using namespace std;
typedef long long ll;
//typedef __int128 lll;
//const int N=100000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-9;
const int INF = 0x3f3f3f3f;
inline ll read(){
long long x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*f;
}
int main()
{
#ifdef DEBUG
freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
//cout.tie(0);
//ll t ;
//scanf("%lld",&t);
//while(t--){
//}
ll n=read(),gc=read();n--;
while(n--){
gc=__gcd(gc,read());
if(gc==1){
printf("1");
return 0;
}
}
ll ans=0;
for(ll i=1;i*i<=gc;i++){
if(gc%i==0){
ans++;
if(i*i!=gc)ans++;
}
}
printf("%lld",ans);
#ifdef DEBUG
printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif
//cout << "Fuck You !" << endl;
return 0;
}