ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

PAT_A1096#Consecutive Factors

2019-07-08 19:53:52  阅读:328  来源: 互联网

标签:factor PAT factors ans 因数 A1096 consecutive Consecutive


Source:

PAT A1096 Consecutive Factors (20 分)

Description:

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<).

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:

630

Sample Output:

3
5*6*7

Keys:

  • 模拟题

Attention:

  • 注意质数的情况

Code:

 1 /*
 2 Data: 2019-07-08 19:35:10
 3 Problem: PAT_A1096#Consecutive Factors
 4 AC: 31:02
 5 
 6 题目大意:
 7 正整数N可以分解为多组因数乘积的形式,选择含有最长连续因数的一组,打印该连续因数
 8 因数中不含1,打印序列递增且较小的
 9 */
10 #include<cstdio>
11 #include<vector>
12 #include<cmath>
13 using namespace std;
14 typedef long long LL;
15 
16 int main()
17 {
18     LL n;
19     scanf("%lld", &n);
20     vector<LL> ans,temp;
21     for(LL i=2; i<=(LL)sqrt(1.0*n); i++)
22     {
23         LL sum=1;
24         temp.clear();
25         for(LL j=i; j<=n; j++)
26         {
27             sum *= j;
28             if(n%sum != 0)
29                 break;
30             temp.push_back(j);
31         }
32         if(temp.size() > ans.size())
33             ans = temp;
34     }
35     if(ans.size()==0)
36         printf("1\n%lld", n);
37     else
38         printf("%d\n", ans.size());
39     for(int i=0; i<ans.size(); i++)
40         printf("%d%c", ans[i], i==ans.size()-1?'\n':'*');
41 
42     return 0;
43 }

 

标签:factor,PAT,factors,ans,因数,A1096,consecutive,Consecutive
来源: https://www.cnblogs.com/blue-lin/p/11153316.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有