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. 阿里投资Magic Leap 是美酒还是毒药?

    Leap 是美酒还是毒药?" title="阿里投资Magic Leap 是美酒还是毒药?"> 土豪阿里又摊上"大事"了!但这次不是让人头痛的假 ...

  2. Leetcode 703题数据流中的第K大元素(Kth Largest Element in a Stream)Java语言求解

    题目链接 https://leetcode-cn.com/problems/kth-largest-element-in-a-stream/ 题目内容 设计一个找到数据流中第K大元素的类(class) ...

  3. 无线城域网 WMAN

    无线城域网 WMAN (Wireless Metropolitan Area Network) 1.1.概述 2002 年 4 月通过了 802.16 无线城域网的标准.欧洲的 ETSI 也制订类似的 ...

  4. USB小白学习之路(6) IIC EEPROM读取解析

    IIC EEPROM读取解析 1. 编译错误处理(这里可以忽略) 在解压包解压了程序后,直接编译,出现如下错误. *** WARNING L14: INCOMPATIBLE MEMORY MODEL ...

  5. Python 十大语法

    前言 Python 是一种代表简单思想的语言,其语法相对简单,很容易上手.不过,如果就此小视 Python 语法的精妙和深邃,那就大错特错了.本文精心筛选了最能展现 Python 语法之精妙的十个知识 ...

  6. GO - if判断,for循环,switch语句,数组的使用

    1.if - else if - else的使用 package main import "fmt" func main() { // 1.简单使用 var a=10 if a== ...

  7. SpringBoot图文教程9—SpringBoot 导入导出 Excel 「Apache Poi」

    有天上飞的概念,就要有落地的实现 概念十遍不如代码一遍,朋友,希望你把文中所有的代码案例都敲一遍 先赞后看,养成习惯 SpringBoot 图文教程系列文章目录 SpringBoot图文教程1「概念+ ...

  8. Day 3 DP

    1. P1015 精卫填海 01背包 + 判断 #include <iostream> using namespace std; , MAXV = ; int v, n, m, f[MAX ...

  9. 图解MySQL索引(上)—MySQL有中“8种”索引?

    关于MySQL索引相关的内容,一直是一个让人头疼的问题,尤其是对于初学者来说.笔者曾在很长一段时间内深陷其中,无法分清"覆盖索引,辅助索引,唯一索引,Hash索引,B-Tree索引--&qu ...

  10. Postgresql存放数组形式的数据

    Postgres 数据库允许把字段定义为可变长度的数组.数据类型既可以是内置类型,也可以是用户自定义的类型或枚举类型. 例如: 创建表 create table demo(name text,subj ...