Advertisement
YEZAELP

PROG-1165: จำนวนตัวหารร่วม

Feb 5th, 2022
984
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. using lli = long long;
  5.  
  6. int main(){
  7.  
  8.     int n;
  9.     scanf("%d", &n);
  10.  
  11.     lli gcd;
  12.     scanf("%lld", &gcd);
  13.     for(int i=2;i<=n;i++){
  14.         lli x;
  15.         scanf("%lld", &x);
  16.         gcd = __gcd(x, gcd);
  17.     }
  18.  
  19.     int cnt = 0;
  20.     lli sq = (lli) sqrt(gcd);
  21.     for(lli i=1;i<=sq;i++) cnt += (gcd % i == 0);
  22.  
  23.     if(sq * sq == gcd) printf("%d", 2 * cnt - 1);
  24.     else printf("%d", 2 * cnt);
  25.  
  26.     return 0;
  27. }
Advertisement
RAW Paste Data Copied
Advertisement