Common Divisors
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 (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

Copy
5
1 2 3 4 5
output

Copy
1
input

Copy
6
6 90 12 18 30 18
output

Copy
4

题意:

给你n个数,找出这n个公因数的个数

思路:

这些公因数的值不会超过他们的最大公因数,因此我们要找到这n个数的最大公因数
看这个最小的最大公因数minn有多少个因子,现在从1找到sqrt(minn),或写成i*i<=minn
如果这个因子的平方等于minn那就只算一个,否则找到了i是minn的因子,就可知道n/i也是minn的因子,所以要加上2个

注意:

最好用scanf,如果用cin要加上流加速,否则会TLE

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int amn=4e5+;
ll a[amn];
ll gcd(ll a,ll b){
return !b?a:gcd(b,a%b);
}
int main(){
ios::sync_with_stdio(); ///以后要习惯性地加上流加速
int n;
cin>>n; ///以后大数据时用cin还是要加上流加速,或直接用scanf,没加前在test5总TLE
for(int i=;i<=n;i++){
cin>>a[i];
}
ll minn=a[];
for(int i=;i<=n;i++){
minn=min(gcd(minn,a[i]),minn); ///找出他们中的一个最小的最大公因数,记为minn
if(minn==){printf("1\n");return ;} ///如果是1就直接输出后退出
}
// cout<<minn<<endl;
ll ans=;
for(ll i=;i*i<=minn;i++){ ///看这个最小的最大公因数minn有多少个因子,现在从1找到sqrt(minn),或写成i*i<=minn
if(i*i==minn)ans++; ///如果这个因子的平方等于minn那就只算一个
else if(minn%i==)ans+=; ///否则找到了i,就可知道n/i,所以要加上2个
}
printf("%lld\n",ans);
}
/***
给你n个数,找出这n个公因数的个数
这些公因数的值不会超过他们的最大公因数,因此我们要找到这n个数的最大公因数
看这个最小的最大公因数minn有多少个因子,现在从1找到sqrt(minn),或写成i*i<=minn
如果这个因子的平方等于minn那就只算一个,否则找到了i是minn的因子,就可知道n/i也是minn的因子,所以要加上2个
注意最好用scanf,如果用cin要加上流加速,否则会TLE
***/

[gcd]Codeforces Common Divisors的更多相关文章

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

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

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

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

  3. B - Common Divisors (codeforces)数论算法基本定理,唯一分解定理模板

    You are given an array aa consisting of nn integers. Your task is to say the number of such positive ...

  4. CF #579 (Div. 3) C.Common Divisors

    C.Common Divisors time limit per test2 seconds memory limit per test256 megabytes inputstandard inpu ...

  5. Codeforces Round #117 (Div. 2) D.Common Divisors(KMP最小循环节)

    http://codeforces.com/problemset/problem/182/D 题意:如果把字符串a重复m次可以得到字符串b,那么我们称字符串a为字符串b的一个因子,现在给定两个字符串S ...

  6. Common Divisors CodeForces - 1203C

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

  7. [Lyft Level 5 Challenge 2018 - Elimination Round][Codeforces 1033D. Divisors]

    题目链接:1033D - Divisors 题目大意:给定\(n\)个数\(a_i\),每个数的约数个数为3到5个,求\(\prod_{i=1}^{n}a_i\)的约数个数.其中\(1 \leq n ...

  8. Maximal GCD CodeForces - 803C (数论+思维优化)

    C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  9. C. Enlarge GCD Codeforces Round #511 (Div. 2)【数学】

    题目: Mr. F has nn positive integers, a1,a2,…,an. He thinks the greatest common divisor of these integ ...

随机推荐

  1. Python——用turtle模块画海龟的第一步

    */ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:text.cpp * 作者:常轩 * 微信公众号:Worldhe ...

  2. JavaScript学习总结之数组常用的方法和属性

    先点赞后关注,防止会迷路寄语:没有一个冬天不会过去,没有一个春天不会到来. 前言数组常用的属性和方法常用属性返回数组的大小常用方法栈方法队列方法重排序方法操作方法转换方法迭代方法归并方法总结结尾 前言 ...

  3. 放弃了程序员互联网高薪,跑去事业单位做IT的尴尬

    “你是程序员对吧?”“是啊,怎么了?”“那你帮我修一下电脑吧.”我原来也是一个重点大学毕业,基本上事业里面搞IT就干这些事情,要是以前,我肯定会想,我是程序员和修电脑有啥关系. 但是自从进了事业单位, ...

  4. DSO 运行 —— dso_ros + Android 手机摄像头

    转载请注明出处,谢谢 原创作者:Mingrui 原创链接:https://www.cnblogs.com/MingruiYu/p/12425855.html 本文要点: dso 配置安装 dso 离线 ...

  5. docker安装与环境部署

    使用docker搭建环境 摘要 install docker start docker install docker-compose 部署upload-labs/sqli-labs 部署dvwa 部署 ...

  6. Flutter 拖拽排序组件 ReorderableListView

    注意:无特殊说明,Flutter版本及Dart版本如下: Flutter版本: 1.12.13+hotfix.5 Dart版本: 2.7.0 ReorderableListView是通过长按拖动某一项 ...

  7. Ubuntu18.04LTS 文件系统简记

    Ubuntu18.04LTS 文件系统 了解Linux文件系统是熟悉掌握使用Linux系统的第一步 首先安装名为tree的工具 sudo apt install tree 运行 tree --help ...

  8. Yuchuan_Linux_C编程之一 Vim编辑器的使用

    一.整体大纲 二.Vim 编辑器的使用 vi -- vim    vim是从vi发展过来的一款文本编辑器    vi a.txt    前提: 安装了vim软件 工作模式: 1. 命令模式 -- 打开 ...

  9. ZXingObjC直接引用第三方工程使用方法

    1.下载ZXingObjc压缩包,解压缩. 2.将文件拷贝到项目工程目录下 3.到工程目录中ZXingObjc文件夹中将ZXing的执行文件拖拽到项目中. 4.点击项目targets ——>Bu ...

  10. 利用Java实现指定文件夹下的照片以自定义格式移动

    前几天本猿的大学同学,一个漂亮的小姐姐工作时遇到了一个问题,她的需求是,在公司局域网的电脑上下载大量的图片重命名成指定得1.2.3.....以此类推,需要当天完成,我就临时给写了一个小demo. 我的 ...