C. Common Divisors (Codeforces Round #579 )

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

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

#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
typedef long long ll;
using namespace std;
const int INT=1e6+5;
#define lson rt<<1, l, m  
#define rson rt<<1|1, m+1, r
#define read(x) scanf("%d",&x)
#define lread(x) scanf("%lld",&x);
#define pt(x) printf("%d\n",(x))
#define cn cin>>
#define ct cout<<
#define en <<endl
#define rep(j,k) for (int i = (int)(j); i <= (int)(k); i++)
#define mem(s,t) memset(s,t,sizeof(s))
#define re return 0;
#define TLE std::ios::sync_with_stdio(false);
ll a[100000+5],b[10000+5];
priority_queue<ll>Ql, Q2;
 int main () 
{ 
    TLE; 
    LL T, n-, m, MX, In Flag, K = 0 , CNT = 0 ; 
    CN n-; 
    REP ( . 1 , n-) 
    { 
        CN m; 
        K = __gcd (m, K ); // libraries 
    } 
    REP ( . 1 , sqrt (k)) 
    { 
        IF (% K I) Continue ;
         the else 
        { 
            CNT ++ ;
             IF (K = I / I) CNT ++! ; // count sqrt (k) to the right the divisor, is an optimization 

     }
  }
  CT CNT EN;
  Re;
}

 

Guess you like

Origin www.cnblogs.com/Shallow-dream/p/11415943.html