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. 初识Machine Learning

    What is Machine Learning 定义 Arthur Samuel:Field of study that gives computers the ability to learn w ...

  2. iOS 客户端与服务端做时间同步

    需求 我们做客户端的时候,有时会需要对客户端与服务器的时间进行同步,比如抢购活动.倒计时等.这时我们要考虑如何准备地与服务器的时间进行同步,同时防止用户本地的时间有误差时导致的问题. 分析 描述 为了 ...

  3. [开源福利] Arithmetic Generator

    Arithmetic Generator Built with ❤︎ by Simon Ma ✨ A powerful arithmetic generator

  4. 告别ThinkPHP6的异常页面, 让我们来拥抱whoops吧

    春节期间熟悉了TP6, 也写了一个TP6的博客程序,但系统的异常页面实在另外头疼,很多时候无法查看到是哪行代码出的问题. 所以就特别的想把whoops引进来,经过一系列的研究,终于找到了解决的办法: ...

  5. 完整版EXCEL导出 (大框架SpringCloud 业务还是Springboot一套)

    这里用的是easypoi 首先引入jar包 <!-- excel --><dependency> <groupId>cn.afterturn</groupId ...

  6. Java对接微信登录

    今天我们来对接微信开放平台的网站应用登录 首先上文档链接:https://developers.weixin.qq.com/doc/oplatform/Website_App/WeChat_Login ...

  7. 新大陆NB-IoT模块烧写详细过程

    NB-IOT 模块板设置 1. NB-IOT 模块板如下 2.将模块上红色开关 1. 2 向下拨, 3. 4 开关向上拨,如下 3.将黑色开关向左侧拨至 M3 芯片处,如下 4.将模块上启动/下载开关 ...

  8. 【渗透】node.js经典问题

    1.循环问题 当循环调用 require() 时,一个模块可能在未完成执行时被返回.例如以下情况:a.js: exports.done = false; const b = require('./b. ...

  9. SQLyog试用到期的解决方法(仅供个人学习使用,禁止转载或用于商业盈利)

    作者:EzrealYi 本章链接:https://www.cnblogs.com/ezrealyi/p/12434105.html win+r->输入regedit->进入注册表 在计算机 ...

  10. 2020年,如何成为一名 iOS 开发高手!

    2020年对应程序员来说,是一个多灾的年份,很多公司都进行了不同比例的优化和裁员.等疫情得到控制后,将会是找工作的高峰期,从去年的面试经历来看,现在只会单纯写业务代码的人找工作特别难,很多大厂的面试官 ...