PAT(甲级)1096
来源:互联网 发布:vscode代码格式化 编辑:程序博客网 时间:2024/06/06 04:09
1096. Consecutive Factors (20)
Among all the factors of a positive integer N, there may exist several consecutive numbers. For example, 630 can be factored as 3*5*6*7, where 5, 6, and 7 are the three consecutive numbers. Now given any positive N, you are supposed to find the maximum number of consecutive factors, and list the smallest sequence of the consecutive factors.
Input Specification:
Each input file contains one test case, which gives the integer N (1<N<231).
Output Specification:
For each test case, print in the first line the maximum number of consecutive factors. Then in the second line, print the smallest sequence of the consecutive factors in the format "factor[1]*factor[2]*...*factor[k]", where the factors are listed in increasing order, and 1 is NOT included.
Sample Input:630Sample Output:
35*6*7
#include <iostream>#include <cmath>#include <vector>////////////////////////////////////////////////////////////1.better to find the first factor,otherwise this problem//will be much more complex//2.whether to find its subfactors first and then divide//is better?//////////////////////////////////////////////////////////using namespace std;int main(){int n;int i,j,tmp;cin >>n;vector<int> ans(1,n),v;int limit =sqrt(n);for(i=2;i<=limit;i++){v.clear();tmp = n;for(j = i ;j<=limit;j++){if(tmp % j == 0){v.push_back(j);tmp /=j;} else break;}if(ans.size() < v.size() || (ans.size() == v.size() &&ans[0] > v[0])){ans = v;}}vector<int>::iterator iter=ans.begin();tmp =ans.size();cout <<tmp <<endl;while(tmp != 1){cout <<*iter <<'*';tmp--;iter++;}cout <<*iter <<endl;return 0;}
- PAT(甲级)1096
- *浙大PAT甲级 1096
- PAT甲级1096
- PAT 甲级
- PAT甲级 A1025.PAT RANKING
- PAT 甲级 1025 PAT Ranking
- PAT(甲级)1003
- PAT(甲级)1004
- PAT(甲级)1005
- PAT(甲级)1006
- PAT(甲级)1007
- PAT(甲级)1008
- PAT(甲级)1009
- PAT(甲级)1010
- PAT(甲级)1011
- PAT(甲级)1012
- PAT(甲级)1013
- PAT(甲级)1014
- 默认调用无参构造函数 用的非常到位
- 【树DP】[CodeForces - 581F]Zublicanes and Mumocrates
- 设计模式六大原则(2):里氏替换原则
- 知识点(不断更新)
- 小文件与CombineFileInputFormat
- PAT(甲级)1096
- C#中关于@的用法
- Jackson 高性能的JSON处理 ObjectMapper
- 图形验证码one
- JavaScript:instanceof
- LeetCode题解——Add Digits
- PAT(甲级)1097
- JSP解析JSONObject类型对象出现null object异常解决方案
- Mybatis系列(二)配置