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;
}