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:

  1. 630

Sample Output:

  1. 3
  2. 5*6*7
  3.  
  4. 想来想去只能用暴力法
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. using namespace std;
  5. int N, num = , first = -;
  6. int main()
  7. {
  8. cin >> N;
  9. for (int i = ; i <= (int)sqrt(N*1.0); ++i)//2~根号N
  10. {
  11. if (N%i == )
  12. {
  13. int nn = ;
  14. for (int j = i; N%j == ; j*=i+nn)//从i开始的连续数字,确保能连续除下去,而不是除以一个数字
  15. ++nn;
  16. if (nn > num)//更新最长数字串
  17. {
  18. first = i;
  19. num = nn;
  20. }
  21. }
  22. }
  23. if (num == )//N就是质数
  24. cout << << endl << N << endl;
  25. else
  26. {
  27. cout << num << endl;
  28. for (int i = ; i < num; ++i)
  29. cout << first + i << (i == num - ? "" : "*");
  30. }
  31. return ;
  32. }

PAT甲级——A1096 Consecutive Factors【20】的更多相关文章

  1. PAT甲级——1096 Consecutive Factors (数学题)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/91349859 1096 Consecutive Factors  ...

  2. PAT 甲级 1096 Consecutive Factors

    https://pintia.cn/problem-sets/994805342720868352/problems/994805370650738688 Among all the factors ...

  3. PAT Advanced 1096 Consecutive Factors (20) [数学问题-因子分解 逻辑题]

    题目 Among all the factors of a positive integer N, there may exist several consecutive numbers. For e ...

  4. PAT A1096 Consecutive Factors (20 分)——数字遍历

    Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam ...

  5. PAT (Advanced Level) Practise - 1096. Consecutive Factors (20)

    http://www.patest.cn/contests/pat-a-practise/1096 Among all the factors of a positive integer N, the ...

  6. 1096. Consecutive Factors (20)

    Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam ...

  7. A1096. Consecutive Factors

    Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam ...

  8. 【PAT甲级】1096 Consecutive Factors (20 分)

    题意: 输入一个int范围内的正整数,输出它最多可以被分解为多少个连续的因子并输出这些因子以*连接. trick: 测试点5包含N本身是一个素数的数据,此时应当输出1并把N输出. 测试点5包含一个2e ...

  9. PAT甲题题解-1096. Consecutive Factors(20)-(枚举)

    题意:一个正整数n可以分解成一系列因子的乘积,其中会存在连续的因子相乘,如630=3*5*6*7,5*6*7即为连续的因子.给定n,让你求最大的连续因子个数,并且输出其中最小的连续序列. 比如一个数可 ...

随机推荐

  1. java OOP第二章_封装

    一. 封装: 属性通过private访问修饰符将其设置为私有的,只有当前类中可以访问,同时提供通过public访问修饰符的公共方法可以给任何类中访问. 通常针对属性提供公共的setter方法进行赋值, ...

  2. 导出sheet到新文件夹当中

    Sub 导出当前客户达成分析()Application.ScreenUpdating = FalsemyName1 = Sheets("日期统计表").Range("B1 ...

  3. Sublime Text最舒服的主题

    Theme - Afterglow (官网链接) 贴上 preferences -> settings 里面的配置 { "theme": "Afterglow-gr ...

  4. leetcode-157周赛-5216-统计元音字母序列的数目

    题目描述: 方法:倒推 class Solution(object): def countVowelPermutation(self, n): MOD = 10 ** 9 + 7 a=e=i=o=u= ...

  5. thinkphp switch标签

    用法: <switch name="变量" > <case value="值1" break="0或1">输出内容1 ...

  6. The Preliminary Contest for ICPC Asia Nanjing 2019 C. Tsy's number 5

    https://nanti.jisuanke.com/t/41300 题意:求\(\sum_{i=1}^n\phi(i)\phi(j)2^{\phi(i)\phi(j)}\) \(f_i=\sum_{ ...

  7. str和byte的区别

    bytes 1.bytes对象只负责以二进制字节序列的形式记录所需记录的对象,至于该对象到底表示什么(比如到底是什么字符)则由相应的编码格式解码所决定 2.bytes是Python 3中特有的,Pyt ...

  8. https 生成秘钥

    #生成一个RSA秘钥 openssl genrsa -des3 -out a_com.key 1024 #生成一个证书请求openssl req -new -key a_com.key -out a_ ...

  9. RPC远程过程调用实例详解

    1.创建IDL文件,定义接口. IDL文件可以由uuidgen.exe创建. 首先找到系统中uuidgen.exe的位置,如:C:\Program Files\Microsoft Visual Stu ...

  10. Mybatis笔记 – 入门程序开发

    一.Mybatis开发环境 JDK:jdk_1.7 Eclipse:Oxygen.1 Release (4.7.1) MySQL:MySQL Servr 5.7 1.添加相关ja r包 mybatis ...