LightOJ 1035 Intelligent Factorial Factorization
2012-12-02 20:20
375 查看
题目链接 http://lightoj.com/volume_showproblem.php?problem=1035
题意:计算N!的素数分解式,N最大100,注意输出格式
题意:计算N!的素数分解式,N最大100,注意输出格式
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; const int NUM=105; int prime[NUM],indexmax[NUM],factor[NUM]; //定义index[NUM]会编译错误……LightOJ是有多纠结…… int Num_Prime=0,id; bool visit[NUM]; int n; void Prime () //素数打表prime数组从1开始 { for (int i=2;i<NUM;i++) if (!visit[i]) { prime[++Num_Prime]=i; for (int j=i+i;j<NUM;j+=i) visit[j]=true; } } void Input () { id=0; scanf ("%d",&n); memset(indexmax,0,sizeof(indexmax)); memset(factor,0,sizeof(factor)); for (int k=n;k>1;k--) //factor数组从0开始 { int temp=k,t; for (int i=1;i<=Num_Prime && prime[i] <= temp; i++) { t=0; while (temp%prime[i] == 0) { t++; temp/=prime[i]; } if (t!=0) { if (indexmax[prime[i]] == 0) factor[id++]=prime[i]; //记录最小公倍数中的素因子 indexmax[prime[i]]+=t; //记录素因子p[i]的个数 } } } } void Deal () { printf("%d =",n); sort(factor,factor+id); for (int i=0;i<id;i++) { printf(" %d (%d)",factor[i],indexmax[factor[i]]); if (i!=id-1) printf(" *"); } printf("\n"); } int main () { int T; scanf("%d",&T); Prime (); for (int cas=1;cas<=T;cas++) { Input (); printf("Case %d: ",cas); Deal (); } return 0; } /* 1 17 Out: Case 1: 17 = 2 (15) * 3 (6) * 5 (3) * 7 (2) * 11 (1) * 13 (1) * 17 (1) */
相关文章推荐
- lightoj 1035 Intelligent Factorial Factorization 因式分解
- LightOJ 1035 Intelligent Factorial Factorization
- LightOJ 1035 Intelligent Factorial Factorization 全排列
- LightOJ 1035 Intelligent Factorial Factorization 因子分解水题
- Intelligent Factorial Factorization LightOJ - 1035
- LightOJ 1035 Intelligent Factorial Factorization
- LightOJ 1035 Intelligent Factorial Factorization [预处理+一半的 质因子分解]【数论】
- LightOJ1035 Intelligent Factorial Factorization(算数基本定理)
- LightOJ - 1035 Intelligent Factorial Factorization 质因子分解
- LightOJ 1035 - Intelligent Factorial Factorization (求因子)
- Light OJ 1035 - Intelligent Factorial Factorization
- Light OJ 1035 Intelligent Factorial Factorization
- 【LightOJ】1045 - Digits of Factorial(数论)
- lightoj 1045 - Digits of Factorial (数学-log运用--阶乘进制位数)
- lightoj1045 - Digits of Factorial
- LightOJ - 1035 (数论)
- LightOJ - 1045 Digits of Factorial
- lightoj1045 - Digits of Factorial
- LightOJ 1045 Digits of Factorial【进制问题】
- lightoj 1035【暴力】