题目链接:https://codeforces.com/contest/1203/problem/C
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).
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.
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).
5 1 2 3 4 5
1
6 6 90 12 18 30 18
4
题意:给你一个序列,求所有元素的最大公约数的约数个数
思路:注意点 所有类型必须是long long型
代码如下:
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<cmath> using namespace std; #define ll long long int ll a[400010]; ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); } ll ApproximateNumber(ll n) { ll cnt=0; for(ll i=1;i*i<=n;i++) if(n%i==0) { if(i*i==n) cnt++; else cnt+=2; } return cnt; } int main() { ll n;scanf("%lld",&n); cin>>a[1]; ll ans=a[1]; for(ll i=2;i<=n;i++) { scanf("%lld",&a[i]); ans=gcd(ans,a[i]); } cout<<ApproximateNumber(ans)<<endl; return 0; }