zoukankan      html  css  js  c++  java
  • 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;
    } 
    
    
  • 相关阅读:
    Data Guard相关参数学习介绍
    Android打包失败Proguard returned with error code 1. See console
    Extjs4 类的定义和扩展
    c#中常用的异常类型
    cocos2d-x过程动作CCProgressTo示例学习笔记
    欧拉函数
    sae上屏蔽错误显示并查看错误日志
    在wdcp环境下架设VSFTPD虚拟用户只上传功能服务器
    Android开发匹配字符笔记
    setImageResource与setImageBitmap的区别
  • 原文地址:https://www.cnblogs.com/ylrwj/p/11773432.html
Copyright © 2011-2022 走看看