[cpp] //清橙OJ A1036.分解質因數 //http://www.tsinsen.com/ViewGProblem.page?gpid=A1036 #include<stdio.h> #include<string.h> #define MAXS 10005 int main() { int a,b,i,j,k,count=0,prime[MAXS],mark[MAXS]={0},ans[MAXS]; memset(prime,0,MAXS*sizeof(int)); for(i=2;i<MAXS;i++) { if(mark[i])continue; prime[count++]=i; for(j=i*i;j<MAXS;j+=i)mark[j]=1; } while(~scanf("%d %d",&a,&b)) { for(k=a;k<=b;k++) { if(!mark[k]){printf("%d=%d\n",k,k);continue;} memset(ans,0,MAXS*sizeof(int)); int temp=k; for(i=0;prime[i]<=temp;i++) { if(temp%prime[i]==0) { ans[prime[i]]++; temp/=prime[i--]; } }//for for(i=0;!ans[prime[i]];i++); printf("%d=%d",k,prime[i]); while(--ans[prime[i]])printf("*%d",prime[i]); for(i++;i<count;i++) { www.2cto.com while(ans[prime[i]]--) { printf("*%d",prime[i]); } } printf("\n"); }//for }//while return 0; }