题意:求 n 个数字的约数的个数
做法:已知 x 是n个数字的最大公约数,x可以分解为t个质数,216 = 2^3 * 3^3, 216的约数个数 4 * 4
#include <stdio.h> #include <string.h> #include <list> #include <algorithm> using namespace std; typedef long long ll; typedef double db; const int maxsz = 10001; const int maxn = 4e5+1; //int cnt[maxsz]; ll a[maxn]; bool isprime ( ll num ) { if (num == 1) return false; for (ll i = 2; i * i <= num; i++) if (num % i == 0) return false; return true; } int main () { int t; ll n; scanf("%d", &t); for (int i = 1; i <= t; i++) scanf("%lld", a+i); n = a[1]; for (int i = 2; i <= t; i++) n = __gcd(n, a[i]); ll ans = 1; for (ll i = 2; i * i <= n; i++) { ll cnt = 1; if ( isprime ( i ) ) { while ( n % i == 0 ) { n /= i; cnt++; } } ans = ans * cnt; } if (n - 1) ans *= 2; printf("%lld ", ans); return 0; }