PAT (Advanced Level) Practice 1096 Consecutive Factors (20 分)
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:
630
Sample Output:
3
5*6*7
这题虽然是20分,但是一点也不水,需要认真想一想,2^31次方大概是12!~13!之间,基于此我们可以暴力,大概就是去找它的连续因子,随时更新答案,要注意素数的情况特判~
#include<bits/stdc++.h>
#define ll long long
#define rg register ll
using namespace std;
int main()
{
ll n,maxx=0,ans=0;
cin>>n;
for(rg i=2;i<=sqrt(n);i++)
{
ll tep=1,len=0;
for(rg j=i;j<=sqrt(n);j++)
{
tep*=j;
if(n%tep)break;
len++;
}
if(maxx<len)
{
maxx=len;
ans=i;
}
}
if(!ans)
{
cout<<1<<endl<<n<<endl;
}
else
{
cout<<maxx<<endl;
for(rg i=ans;i<ans+maxx;i++)
{
i==ans+maxx-1?cout<<i<<endl:cout<<i<<"*";
}
}
while(1)getchar();
return 0;
}
- 用R语言复盘美国总统大选结果~
- 最新Apache Spark平台的NLP库,助你轻松搞定自然语言处理任务
- 使用Seq2Seq+attention实现简单的Chatbot
- R语言可视化——用ggplot构造期待已久的雷达图
- 【实战】最新Deep Learning with Keras图书加代码,教你从零开发一个复杂深度学习模型(附下载)
- 基于zabbix 自动抓取每天监控数据!/usr/local/python/bin/python3.5
- 大过年的,一起来用Seq2Seq来作对联吧!
- python3 下调用zabbix api 获取多个机房的IP
- TensorFlow从0到1 - 14 - 交叉熵损失函数——防止学习缓慢
- 用优雅的配色来缔造图表专业主义~
- python文件名与包名冲突
- python3 Zabbix监控-api的使用-python
- 安装python虚拟环境
- 各种排序算法的分析及java&python实现
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Android实现移动小球和CircularReveal页面切换动画实例代码
- Android4.4+ 实现半透明状态栏(Translucent Bars)
- Android弹出dialog后无法捕捉back键的解决方法
- Android编程设置屏幕亮度的方法
- 利用SurfaceView实现下雨与下雪动画效果详解(Kotlin语法)
- Android WebView的使用方法及与JS 相互调用
- Android标题栏上添加多个Menu按钮的实例
- Android编程解析XML文件的方法详解【基于XmlPullParser】
- 教你3分钟了解Android 简易时间轴的实现方法
- Android网络技术HttpURLConnection详解
- Ubuntu16.04下CUDA8.0和CUDA9.0共存
- Ubuntu 20.04 开启隐藏录音降噪功能(推荐)
- 解密 Linux 版本信息的方法
- ubuntu20.04连接wifi的方法(2种)
- 服务器Centos部署MySql并连接Navicat过程详解