CodeForce Round 579 Div 3 C. Common Divisors

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(1n4×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(1ai1012), 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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值