• B


    You are given an array aa consisting of nn integers.

    Your task is to say the number of such positive integers xx such that xx 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 aa will be [2,4,6,2,10][2,4,6,2,10], then 11 and 22 divide each number from the array (so the answer for this test is 22).

    Input

    The first line of the input contains one integer nn (1n41051≤n≤4⋅105) — the number of elements in aa.

    The second line of the input contains nn integers a1,a2,,ana1,a2,…,an (1ai10121≤ai≤1012), where aiai is the ii-th element of aa.

    Output

    Print one integer — the number of such positive integers xx such that xx 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算法就可以,然后直接求最大公因数的因子个数
    #include<iostream>
    #include<cstring>
    using namespace std;
    const int maxn=4e5+10;
    typedef long long ll;
    ll a[maxn];
    int x,y;
    ll gcd(ll a,ll b)                 //自定义函数求最大公约数
    {
        if(a%b==0)                    //终止条件
            return b;                   //b及为最大公约数
        else
            return gcd(b,a%b);
    }
    int main()
    {
        ll n;
        cin>>n;
        for(int i=0;i<n;i++) 
           cin>>a[i]; 
        ll k=a[0];
        for(int i=1;i<n;i++) 
           k=gcd(k,a[i]);
        int ans = 0;
        for (int i = 1; i * 1ll * i <= k; ++i) 
        {
            if (k % i == 0) 
            {
                ans++;
                if (i != k / i) //不能写i*i!=k,会溢出
                {
                    ans++;
                }
            }
        }
        cout << ans << endl;
    return 0;
    } 
    
    
  • 相关阅读:
    Linux PXE无人值守网络装机
    Linux 自动化部署DNS服务器
    Linux DNS服务配置
    Mysql数据库基础学习笔记
    Linux AIDE(文件完整性检测)
    mysql:[Err] 1068
    sql的date、时间函数、时间戳
    hive之建立分区表和分区
    excel转sql代码
    spark-submit之使用pyspark
  • 原文地址:https://www.cnblogs.com/ylrwj/p/11773432.html
Copyright © 2020-2023  润新知