LightOJ 1035 - Intelligent Factorial Factorization (求因子)

1035 - Intelligent Factorial Factorization
Time Limit: 0.5 second(s)Memory Limit: 32 MB

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

Input

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 factorizationof 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

3

2

3

6

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 replacespace with '.') is

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


题意:分解n!成样例的输出样式

思路:暴力写写就好。。


ac代码:

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stack>
#include<set>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#define MAXN 1001000
#define LL long long
#define ll __int64
#define INF 0x7fffffff
#define mem(x) memset(x,0,sizeof(x))
#define PI acos(-1)
#define eps 1e-10
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
//head
int ans[110];
int main()
{
    int t,n,i,j;
    int cas=0;
    scanf("%d",&t);
    while(t--)
    {
    	mem(ans);
    	scanf("%d",&n);
		for(i=2;i<=n;i++)
		{
			int x=i;
			for(j=2;j<=x;j++)
			{
				if(x%j==0)
				{
					int cnt=0;
					while(x%j==0)
					{
						cnt++;
						x/=j;
					}
					ans[j]+=cnt;
				}
				if(x==1)
				break;
			}
		}
		printf("Case %d: %d = ",++cas,n);
		printf("2 (%d)",ans[2]);
		for(i=3;i<=100;i++)
		if(ans[i])
		printf(" * %d (%d)",i,ans[i]);
		printf("\n");
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值