LCM Cardinality
#include <cstdio> #include <cstring> #define ll long long int const MAX = 1e5; int const LIM = 2e9; int fac[MAX], cnt, n; int gcd(int a, int b) { while(b) { int tmp = a; a = b; b = tmp % b; } return a; } ll lcm(int a, int b) { return (ll) a * b / gcd(a, b); } void cal() { cnt = 0; for(int i = 1; i * i <= n; i++) { if(n % i == 0) { fac[cnt++] = i; fac[cnt++] = n / i; } if(fac[cnt - 1] == fac[cnt - 2]) cnt --; } } int main() { while(scanf("%d", &n) != EOF && n) { cal(); int ans = 0; for(int i = 0; i < cnt; i++) for(int j = i; j < cnt; j++) if(lcm(fac[i], fac[j]) == n) ans ++; printf("%d %d\n", n, ans); } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
UVA 10892 LCM Cardinality (分解因数+暴力)
原文地址:http://blog.csdn.net/tc_to_top/article/details/47376285