PAT A1096 consecutive factors
来源:互联网 发布:酶标仪数据怎么看 编辑:程序博客网 时间:2024/05/17 01:01
还是得用乘积来算啊。。第一次做的方法是一直除j,然后j自增,计数。一直有4分通不过。后来仔细思考了一下,比如120=2*3*4*5,但是120%6=0,不能说120=2*3*4*5*6,所以这种取巧方法不可以。
#include<cstdio>
#include<algorithm>using namespace std;
const int MAXN=100010;
typedef long long ll;
int main(){
ll n;
scanf("%lld",&n);
ll i,j,maxnum=0,maxtag,temp;
int sqnum=0;
ll sqr=(ll)sqrt(1.0*n);
for(i=2;i<=sqr;i++){
temp=i;
j=i;
sqnum=0;
while(n%temp==0){
sqnum++;
j++;
temp*=j;
}
if(sqnum>maxnum){
maxnum=sqnum;
maxtag=i;
}
}
if(maxnum>=1){
printf("%lld\n",maxnum);
for(i=0;i<maxnum;i++){
if(i<maxnum-1) printf("%lld*",maxtag++);
else printf("%lld",maxtag);
}
}else{
printf("1\n");
printf("%lld",n);
}
system("pause");
return 0;
}
0 0
- PAT A1096 consecutive factors
- PAT A1096.Consecutive Factors
- pat-a1096. Consecutive Factors (20)
- PAT A1096. Consecutive Factors (20)
- PAT 1096. Consecutive Factors
- pat 1096 Consecutive Factors
- PAT-Consecutive Factors (20)
- PAT Consecutive Factors (20)
- PAT|1096. Consecutive Factors
- PAT--1096. Consecutive Factors
- 【PAT】1096. Consecutive Factors
- pat 1096. Consecutive Factors
- PAT 1096. Consecutive Factors (20)
- PAT 1096. Consecutive Factors (20)
- PAT 1096. Consecutive Factors (20)
- PAT 1096. Consecutive Factors (20)
- [PAT]1096. Consecutive Factors (20)
- 【PAT】1096. Consecutive Factors (20)
- LeetCode题解–4. Median of Two Sorted Arrays
- Android实现-闹钟-通知
- UVa122:Trees on the level
- [NOIP] [状压DP] NOIP2016Day2 愤怒的小鸟
- Java中Writer的常用类
- PAT A1096 consecutive factors
- android控件使用-----SpannableString
- python爬虫原理解析
- Bean的作用域
- 理解事务的4种隔离级别
- runLoop运行模式示例代码
- Android中线程池的总结
- Android开发 读取assets下的TXT文本一直提示找不到文件
- 牛人写的设计游戏服务器