集训第六周 数学概念与方法 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
ViewCode
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
相关文章推荐
- sed 中带变量的情况
- js,addEventListener参数传递
- textarea长度限制
- mt7601移植到海思3518
- 工作中的程序员如何进阶
- 深入Objective-C的动态特性
- Eclipse中安装Birt插件及基础教程
- ISP模块之RAW DATA去噪(二)--BM3D算法
- Javascript(一)-16-(JS函数_细节2)
- TCP的四层结构及每一层的功能
- Nagios:企业级系统监控方案
- Android studio相关设置及实现存在于工程目录中的视频播放
- leetcode - Unique Binary Search Trees
- 火狐浏览器(Firefox)打开EBS form的设置方法
- ajax 设置Access-Control-Allow-Origin实现跨域访问
- Git简介
- 零java基础搞定微信Server
- iOS企业证书申请
- Javascript(一)-15-(JS函数_细节1)
- 中文情感倾向性分析(IEEE2010)