博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PAT 甲级 1096 Consecutive Factors
阅读量:4330 次
发布时间:2019-06-06

本文共 1376 字,大约阅读时间需要 4 分钟。

 

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:

35*6*7

代码:

#include 
using namespace std;int N;int main() { scanf("%d", &N); for(int i = 13; i >= 1; i --) { for(int j = 2; j * j <= N; j ++) { long long ans = 1; for(int k = j; k - j <= i - 1; k ++) ans *= k; if(N % ans == 0) { printf("%d\n%d", i, j); for(int k = j + 1; k - j <= i - 1; k ++) printf("*%d", k); return 0; } } } printf("1\n%d", N); return 0;}

  枚举连续因子长度 枚举起点终点

 

转载于:https://www.cnblogs.com/zlrrrr/p/10382881.html

你可能感兴趣的文章
react.js
查看>>
P1313 计算系数
查看>>
NSString的长度比较方法(一)
查看>>
Azure云服务托管恶意软件
查看>>
My安卓知识6--关于把项目从androidstudio工程转成eclipse工程并导成jar包
查看>>
旧的起点(开园说明)
查看>>
生产订单“生产线别”带入生产入库单
查看>>
crontab导致磁盘空间满问题的解决
查看>>
java基础 第十一章(多态、抽象类、接口、包装类、String)
查看>>
Hadoop 服务器配置的副本数量 管不了客户端
查看>>
欧建新之死
查看>>
自定义滚动条
查看>>
APP开发手记01(app与web的困惑)
查看>>
笛卡尔遗传规划Cartesian Genetic Programming (CGP)简单理解(1)
查看>>
mysql 日期时间运算函数(转)
查看>>
初识前端作业1
查看>>
ffmpeg格式转换命令
查看>>
万方数据知识平台 TFHpple +Xpath解析
查看>>
Hive实现oracle的Minus函数
查看>>
秒杀多线程第四篇 一个经典的多线程同步问题
查看>>