CF1203B Equal Rectangles

The meaning of problems: find a divisor number of n numbers

Approach: Given that x is the greatest common divisor of n numbers, x t can be decomposed into prime number, 216 = 3 * 2 ^ 3 ^ 3, the number of about several 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\n", ans);
    
    return 0;
}
View Code

 

Guess you like

Origin www.cnblogs.com/Urchin-C/p/11369132.html