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:

  • 注意质数的情况
  • 若n存在因子factor0,使得factor0*factor0>n,则factor0唯一;即其余factor,全部有factor*factor<=n

Code:

 /*
Data: 2019-07-08 19:35:10
Problem: PAT_A1096#Consecutive Factors
AC: 31:02 题目大意:
正整数N可以分解为多组因数乘积的形式,选择含有最长连续因数的一组,打印该连续因数
因数中不含1,打印序列递增且较小的
*/
#include<cstdio>
#include<vector>
#include<cmath>
using namespace std;
typedef long long LL; int main()
{
LL n;
scanf("%lld", &n);
vector<LL> ans,temp;
for(LL i=; i<=(LL)sqrt(1.0*n); i++)
{
LL sum=;
temp.clear();
for(LL j=i; j<=n; j++)
{
sum *= j;
if(n%sum != )
break;
temp.push_back(j);
}
if(temp.size() > ans.size())
ans = temp;
}
if(ans.size()==)
printf("1\n%lld", n);
else
printf("%d\n", ans.size());
for(int i=; i<ans.size(); i++)
printf("%d%c", ans[i], i==ans.size()-?'\n':'*'); return ;
}

PAT_A1096#Consecutive Factors的更多相关文章

  1. 1096. Consecutive Factors (20)

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

  2. PAT1096:Consecutive Factors

    1096. Consecutive Factors (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A ...

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

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

  4. A1096. Consecutive Factors

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

  5. PAT 甲级 1096 Consecutive Factors

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

  6. PAT 1096 Consecutive Factors[难]

    1096 Consecutive Factors (20 分) Among all the factors of a positive integer N, there may exist sever ...

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

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

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

  9. PAT 1096. Consecutive Factors

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

随机推荐

  1. 3、jQuery面向对象

    1.首先介绍callback.js对ajax进行了封装 function ajaxFunction(){ var xmlHttp; try{ // Firefox, Opera 8.0+, Safar ...

  2. USB3.0 对 2.4G WiFi 影响

    Intel的一篇白皮书<USB 3.0 Radio Frequency Interference Impact on 2.4 GHz Wireless Devices>中即清楚地指出,US ...

  3. Linux打开关闭ping

    #关闭 ” >/proc/sys/net/ipv4/icmp_echo_ignore_all #打开 ” >/proc/sys/net/ipv4/icmp_echo_ignore_all

  4. Linux中的特殊权限s、t、i、a

    文件权限除了r.w.x外还有s.t.i.a权限:s:文件属主和组设置SUID和GUID,文件在被设置了s权限后将以root身份执行.在设置s权限时文件属主.属组必须先设置相应的x权限,否则s权限并不能 ...

  5. C++——迭代器

    除了每个容器定义的迭代器外,iterator库内还定义了其他的迭代器. 1.插入迭代器:向容器中插入元素 1.1 back_inserter 1.2 front_inserter 1.3 insert ...

  6. PAT_A1104#Sum of Number Segments

    Source: PAT A1104 Sum of Number Segments (20 分) Description: Given a sequence of positive numbers, a ...

  7. mysql 个人博客应用的建表和相关查询

    一.建表 用户表tb_user create table if not exists tb_user( user_id int auto_increment, ) not null, user_pas ...

  8. cocos2d之创建自己的场景类

    |   版权声明:本文为博主原创文章,未经博主允许不得转载. 1. 首先创建.h的头文件,然后在将一些图片声音素材加到resource文件夹内,最后在创建.cpp文件:         .h头文件中创 ...

  9. Java菜鸟笔记

    System.out.println( ); 会在输出完毕后自动换行 System.out.print( );   在输出完毕后不会自动换行 MyEclipse/Eclipse快捷键: 定位到某一行, ...

  10. android中的Serveice组件

    创建 配置 Service: 1.定义一个继承了Service类的子类 2.在 AndroidManifest.xml清单文件中对开发的Service进行配置 Service和Activity很相似, ...