lightoj1035

maksyuki 发表于 oj 分类,标签:
0

1035 - Intelligent Factorial Factorization

Input

Given an integer N, you have to prime factorize N! (factorial N).

Input starts with an integer T (≤ 125), denoting the number of test cases.

Each case contains an integer N (2 ≤ N ≤ 100).

Output

For each case, print the case number and the factorization of the factorial in the following format as given in samples.

Case x: N = p1 (power of p1) * p2 (power of p2) * ...

Here x is the case number, p1, p2 ... are primes in ascending order.

Sample Input

Output for Sample Input

3236 Case 1: 2 = 2 (1)Case 2: 3 = 2 (1) * 3 (1)Case 3: 6 = 2 (4) * 3 (2) * 5 (1)

Notes

The output for the 3rd case is (if we replace space with '.') is

Case.3:.6.=.2.(4).*.3.(2).*.5.(1)

 

题目类型:素因子分解

算法分析:N!中有素数p的个数为[N/p] + [N/p^2] + [N/p^3] + …由于N不太大,可以先将100以内的素数都打出来,然后从小到大判断每一个素数及其倍数是否满足 N / p ^ k != 0,将结果累加,否则判断下一个素数或者是退出判断