UVA 10892 LCM Cardinality (分解因數+暴力)
LCM Cardinality
A pair of numbers has a unique LCM but a single number can be the LCM of more than one possible pairs. For example 12 is the LCM of (1, 12), (2, 12), (3,4) etc. For a given positive integer N, the number of different integer pairs with LCM is equal to N can be called the LCM cardinality of that number N. In this problem your job is to find out the LCM cardinality of a number.
Input
The input file contains at most 101 lines of inputs. Each line contains an integer N (0 < N < 2*10^9). Input is terminated by a line containing a single zero. This line should not be processed.
Output
For each line of input except the last one produce one line of output. This line contains two integers N and C. Here N is the input number and C is its cardinality. These two numbers are separated by a single space.
Sample Input
2
12
24
101101291
0
Sample Output
2 2
12 8
24 11
101101291 5
題目連結:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1833
題目大意:問n是多少個數對的最小公倍數
題目分析:考慮到n只有2e9,直接分解因數爆搞
#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);
}
}
相關文章
- HDU 4497GCD and LCM(素數分解)GC
- POJ1142 Smith Numbers(數論,分治+暴力,質因數分解)MIT
- HDU44979 GCD and LCM (素因子分解+計數)GC
- 階乘質因數分解
- 【快速因數分解】Pollard's Rho 演算法演算法
- 藍橋杯題庫 BASIC-16 分解質因數
- 暴力列舉- uva11464 - Even Parity
- HDU 4135 Co-prime(容斥原理+分解質因數)
- python將輸入的一個正整數分解質因數(map)Python
- (UVA - 10976)Fractions Again?!(技巧,暴力列舉)FractionAI
- 分數的GCD和LCMGC
- 因數分解演算法、週期查詢演算法(簡化)演算法
- Java分解質因數,如輸入8,輸出8=2*2*2Java
- HDU 1299 Diophantus of Alexandria (公式變形 分解質因數)公式
- 微課|中學生可以這樣學Python(例6.4):因數分解Python
- 16.基數(Cardinality)
- P1075 [NOIP2012 普及組] 質因數分解
- Codeforces 893E Counting Arrays:dp + 線性篩 + 分解質因數 + 組合數結論
- HDU 4497 GCD and LCM(拆素數+組合)GC
- 基數反饋(Cardinality Feedback)
- Cardinality Feedback基數反饋
- 大質數分解模板
- 分解質因數——MOOC《零基礎學Java語言》第7周程式設計題1Java程式設計
- 計數排序+uva11462排序
- LCM介面設計
- CF 1977 C. Nikita and LCM (*1900) 數論
- 南沙信奧塞陳老師解一本通題:2032:【例4.18】分解質因數
- 《整數分解》讀書筆記筆記
- 牛客周賽 Round 50 D[小紅的因式分解] 超級無敵大暴力
- Cardinality
- 選擇率(selectivity)與基數(cardinality)
- 質數判斷、質因子分解、質數篩
- LCM模組生產流程
- 使用 LCM 加速生圖
- 7.40 CARDINALITY
- 求最大質因數
- [atcoder 349] [F - Subsequence LCM]
- Find Terrorists(素數篩選+素因子分解)Error