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 eachnumber 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 (1≤n≤4⋅1051≤n≤4⋅105) — the number of elements in aa.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤10121≤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

  求一组数的共同因数的数目。
     看数据,暴力一个一个看肯定超时。看完这个题,我的第一反应,竟然只知道这些因数一定小于最小的数(废话)。结果思维一直限制,绕在里面出不来。
打了一年了,自己还是....唉,努力训练吧,上题解。
    以下两种解法都需要求出这组数的最大公因数。为什么呢,找到总的最大公因数N,那么剩下的公因数一定小于它。竟然这组数可以整除N,那么也一定可以整除N的因数。
接下来的工作,就是找N的因数个数。
    解法一:直接找,但是不能暴力一个一个for,还是会超时。要知道,一个数N的因数,以sqrt(N)为分界线,一半在左,一半在右。所以我们只需求出<sqrt(n)的部分ans,
ans*2,然后对sqrt(N)特判一下,看看,是否(int)sqrt(N)*(int)sqrt(N)==N.
  
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;
typedef long long ll;
const int maxn=4e5+;
ll tot=;
ll a[maxn];
ll cha[maxn];
ll b[maxn];
int main()
{
ll n;
while(cin>>n)
{
for(int i=;i<n;i++)
scanf("%lld",&a[i]);
ll k=a[];
for(int i=;i<n;i++)
k=__gcd(k,a[i]);
if(k==)
{
printf("1\n");
continue;
}
double mid=sqrt(k);
ll ans=;
for(int i=;i<mid;i++)
{
if(k%i==)
ans++;
}
ans*=;
if((int)mid*mid==k)
ans++;
cout<<ans<<endl;
}
}
  解法二:数论。算术基本定理(摘自csdn):

所以对N进行分解:

  

ll ans=;    
for(ll i=;i*i<=t;i++)
{
if(t%i==)
{
ll cnt=;
while(t%i==)
{
t=t/i;
cnt++;
}
ans=ans*(cnt+);
}
}
if(t>)  //别忘了加
ans*=;
//算是唯一分解定理的一个模板
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;
typedef long long ll;
const int maxn=4e5+;
ll a[maxn];
int main()
{
ll n;
cin>>n;
for(int i=;i<n;i++)
cin>>a[i];
ll t=a[];
for(int i=;i<n;i++)
t=__gcd(t,a[i]);
if(t==)
cout<<""<<endl;
else
{
ll ans=;
for(ll i=;i*i<=t;i++) 
{
if(t%i==)
{
ll cnt=;
while(t%i==)
{
t=t/i;
cnt++;
}
ans=ans*(cnt+);
}
}
if(t>)
ans*=;
cout<<ans<<endl;
}
}

不多说,接着训练!不给自己的acm生涯留遗憾!

B - Common Divisors (codeforces)数论算法基本定理,唯一分解定理模板的更多相关文章

  1. Common Divisors CodeForces - 182D || kmp最小循环节

    Common Divisors CodeForces - 182D 思路:用kmp求next数组的方法求出两个字符串的最小循环节长度(http://blog.csdn.net/acraz/articl ...

  2. Uva10791 唯一分解定理模板

    唯一分解定理: Uva10791 题意: 输入整数n,要求至少两个正整数,使得他们的最小公倍数为n,且这些整数的和最小 解法: 首先假设我们知道了一系列数字a1,a2,a3……an,他们的LCM是n, ...

  3. Common Divisors CodeForces - 1203C

    题意: 给你n个数,让你找出来公因子有多少个.公因子:对于这n个数,都能被这个公因子整除 题解: 只需要找出来这n个数的最大公因子x,然后找出来有多少不同数能把x给整.(因为我们可以保证x可以把这n个 ...

  4. acm数论之旅--唯一分解定理

    题目: 给出n,问n = b^p中p符合该等式的最大值 分析: 先求出所有n的质因子,然后对这m个质因子分类统计,比如 n = 36时,可以分成 2个2,2个3,然后求出所有这些基数的 最大公因数gc ...

  5. [LightOJ 1341] Aladdin and the Flying Carpet (算数基本定理(唯一分解定理))

    题目链接: https://vjudge.net/problem/LightOJ-1341 题目描述: 问有几种边长为整数的矩形面积等于a,且矩形的短边不小于b 算数基本定理的知识点:https:// ...

  6. UVA10791-Minimum Sum LCM(唯一分解定理基本应用)

    原题:https://vjudge.net/problem/UVA-10791 基本思路:1.借助唯一分解定理分解数据.2.求和输出 知识点:1.筛法得素数 2.唯一分解定理模板代码 3.数论分析-唯 ...

  7. [gcd]Codeforces Common Divisors

    Common Divisors time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  8. Codeforces Round #579 (Div. 3) B Equal Rectangles、C. Common Divisors

    B Equal Rectangles 题意: 给你4*n个数,让你判断能不能用这个4*n个数为边凑成n个矩形,使的每个矩形面积相等 题解: 原本是想着用二分来找出来那个最终的面积,但是仔细想一想,那个 ...

  9. 简单数论之整除&质因数分解&唯一分解定理

    [整除] 若a被b整除,即a是b的倍数,那么记作b|a("|"是整除符号),读作"b整除a"或"a能被b整除".b叫做a的约数(或因数),a ...

随机推荐

  1. Web UI设计师需要了解的用栅格化系统指导网页设计

    出处:https://www.jianshu.com/p/9838f217f4f6 致敬,,, ---------------------------------------------------- ...

  2. OpenCV HOGDescriptor 参数图解

    防止以后再次掉入坑中,决定还是在写写吧 OpenCV中的HOG特征提取功能使用了HOGDescriptor这个类来进行封装,其中也有现成的行人检测的接口.然而,无论是OpenCV官方说明文档还是各个中 ...

  3. flask 常用数据模型模板

    1.一对多关系模型 示例代码 class Role(db.Model): """角色表""" __tablename__ = 'roles' ...

  4. 将git本地仓库同步到远程仓库

    同步到远程仓库可以使用git bash 也可以使用tortoiseGit 1.使用git bash 在仓库的所在目录,点击右键选择“Git Bash Here”,启动git bash程序. 然后再gi ...

  5. [LeetCode] 929. Unique Email Addresses 独特的邮件地址

    Every email consists of a local name and a domain name, separated by the @ sign. For example, in ali ...

  6. [LeetCode] 928. Minimize Malware Spread II 最大程度上减少恶意软件的传播之二

    (This problem is the same as Minimize Malware Spread, with the differences bolded.) In a network of ...

  7. 死循环(endless loop)

    死循环 死循环就是一个无法结束的循环.(endless loop / infinite loop) 出现死循环是因为没有设置好结束条件,循环的结束条件很重要,要充分考虑各种边界情况. 以上一篇随笔中的 ...

  8. Power BI Desktop 安装环境

    Power BI Desktop 环境 最低要求 Windows 7/Windows Server 2008 R2 或更高版本 .NET 4.5 Internet Explorer 9 或更高版本 内 ...

  9. Mybatis中xml文件的时间段动态查询

  10. Spark笔记(一)

    简介 Apache Spark 是专为大规模数据处理而设计的快速通用的计算引擎.Spark是UC Berkeley AMP lab (加州大学伯克利分校的AMP实验室)所开源的类Hadoop MapR ...