您的位置:首页 > 其它

集训第六周 数学概念与方法 J题 数论,质因数分解

2015-08-20 11:24 387 查看
Description

Tomorrowiscontestday,Areyouallready?
Wehavebeentrainingfor45days,andallguysmustbetired.But,youaresoluckycomparingwithmanyexcellentboyswhohavenochancetoattendtheProvince-Final.

Now,yourtaskisrelaxingyourselfandmakingthelastpractice.Iguessthatatleastthereare2problemswhichareeasierthanthisproblem.
whatdoesthisproblemdescribe?
Giveyouapositiveinteger,pleasesplitittosomeprimenumbers,andyoucangotitthroughsampleinputandsampleoutput.

Input

Inputfilecontainsmultipletestcase,eachcaseconsistsofapositiveintegern(1<n<65536),oneperline.anegativeterminatestheinput,anditshouldnottobeprocessed.

Output

Foreachtestcaseyoushouldoutputitsfactorassampleoutput(primefactormustcomeforthascending),thereisablanklinebetweenoutputs.

SampleInput

60
12
-1

SampleOutput

Case1.
223151

Case2.
2231

Hint

60=2^2*3^1*5^1

求质因数,使用循环求,数组记录就好


#include"iostream"
#include"cstring"
#include"cstdio"
usingnamespacestd;
constintmaxn=65536+10;
intvis[maxn];
intmain()
{
intn,ans,ca=1;
while(cin>>n&&n>=0)
{
memset(vis,0,sizeof(vis));
ans=n;
inti=2;
while(n!=1)
{
if(n%i==0)
{
vis[i]++;
n/=i;
i=2;
}
else
i++;
}
if(ca!=1)cout<<endl;
cout<<"Case"<<ca++<<"."<<endl;
for(intj=0;j<=ans;j++)
{
if(vis[j]!=0)cout<<j<<""<<vis[j]<<"";
}
cout<<endl;
}
return0;
}


ViewCode


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: