*浙大PAT甲级 1096
来源:互联网 发布:数据库系统软件 编辑:程序博客网 时间:2024/05/17 04:29
这个题目我的思路是i从2到r(等于n)开始遍历,如果r能整除i,如果第一次则标记这个i,r/=i,sum++,继续判断,直到不能整除为止。
到了不能整除时,如果是因为之前r改变过则将r置成n,同时sum=0,i应变成上次标记的值。
AC代码:
#include<iostream>#include<map>#include<cstdio>#include<algorithm>#include<queue>#include<cstring>#include<set>#include<stack>#include<cmath>#include<vector>#include<hash_map>#define ll long long#define inf 24*60*60using namespace std;int main(){ int n; scanf("%d",&n); int maxx=-5; int biaoji; int r=n; int sum=0; int flag=0; int mark; for(int i=2;i<=r;i++) { if(r%i==0) { if(flag==0) { mark=i; flag=1; } sum++; if(sum>maxx) { maxx=sum; biaoji=i; } r/=i; } else { if(flag==1) { sum=0; r=n; flag=0; i=mark; } if(i>sqrt(r)) { break; } } } if(maxx==-5) { printf("1\n"); printf("%d",n); return 0; } printf("%d\n",maxx); for(int i=biaoji-maxx+1;i<=biaoji;i++) { if(i==biaoji-maxx+1) { printf("%d",i); } else { printf("*%d",i); } }}
0 0
- *浙大PAT甲级 1096
- 浙大pat甲级 1023
- 浙大pat甲级 1024
- 浙大pat甲级 1025
- 浙大PAT甲级 1026
- 浙大PAT甲级 1028
- 浙大PAT甲级 1029
- 浙大PAT甲级 1030
- 浙大PAT甲级 1031
- 浙大PAT甲级 1032
- 浙大PAT甲级 1033
- 浙大PAT甲级 1035
- 浙大PAT甲级 1037
- 浙大PAT甲级 1039
- 浙大PAT甲级 1040
- 浙大PAT甲级 1038
- 浙大PAT甲级 1041
- 浙大PAT甲级 1042
- 掌握设计模式
- 为什么学JavaEE来传智播客
- Raml些许细节
- android 开发中获取versionName和versionCode
- tomcat 主项目设置
- *浙大PAT甲级 1096
- codeforces 679B Bear and Tower of Cubes(贪心+dfs)
- SVN + GIT :Android Studio设置忽略文件
- [SQL优化工具]Quest.Central.For.Databases——SQL Tuning for SQL Server
- 关于导航栏总是默认偏移64的解决方案:
- php常用的魔法变量
- AndroidStudio快捷键大全
- 标准C++中string类函数介绍
- C#读写内存操作方式