hdu 2964 Prime Bases(简单数学题)

时间:2023-11-12 18:36:44

按照题意的要求逐渐求解:

  

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int prime[]={,,,,,,,,};
char zhishu[][]={"","2*3","2*3*5","2*3*5*7","2*3*5*7*11","2*3*5*7*11*13",
"2*3*5*7*11*13*17","2*3*5*7*11*13*17*19","2*3*5*7*11*13*17*19*23"};//vector<int>
int mul[];
int xishu[];
int main()
{
int i,n;
mul[]=prime[];
for(i=;i<;i++)
{
mul[i+]=mul[i]*prime[i+];
}
while(scanf("%d",&n)!=EOF&&n)
{
int m=n;
memset(xishu,,sizeof(xishu));
for(i=;i>=;i--)
{
if(mul[i]<=n)
{
xishu[i]=n/mul[i];
n%=mul[i];
}
//printf("");
}
i=;
printf("%d =",m);
if(m&)printf("");
else
{
while(!xishu[i])i++;
printf(" %d*%s",xishu[i],zhishu[i]);
i++;
}
for(;i<;i++)
{ if(xishu[i])
printf(" + %d*%s",xishu[i],zhishu[i]);
}
printf("\n");
} return ;
}