1. 对于题目描述中 list the smallest sequence of the consecutive factors 正确理解是:如果有多组连续因子,输出开头因子最小的那个序列(一开始理解成输出数目最小的那个序列)

2. 想象一下这种情况,2*3*4*5 = 120,4*5*6 = 120,如果只遍历不去改变n,那么会最大连续因子是5的错误结果。但是如果一边遍历,一遍除以n,想象这种情况 2*3*5*7,2*3如果得到6的话,最大的连续个数就是3(5*6*7),但由于一开始把2就除掉,因此会得到2的错误结果。所以也不能一遍遍历一遍除。只能采用对于每一个因子,往下走看看,看看最远能走到哪一步,然后不断更新这个最远的数字。

3. 对于中间那个长度len = j-i要不要加减一,与其硬想,不如debug来确定。

4. 这题对于数学功底的要求是,明白连续的质因子要出现也只会出现在2到根号n以内,如果在2到根号n以内一个质因子都没有,那就输出那个数自身。(其实可能在(sqrt(n),n)之间有一个质因数,只不过数据不强,没测出来)

AC代码

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<bits/stdc++.h>
#include<stdlib.h>
#include<time.h>using namespace std;
typedef long long LL;const int maxn = 10007;
const int MOD = 1000000007;
const int INF = 1000000000;//INF:下确界
const LL SUP = (1LL<<63)-1;//SUP:上确界
const double eps = 1e-5;int main(){LL n;//虽然n是在int范围内,但是后面会涉及乘积 scanf("%lld",&n);LL sqr = (int)sqrt(1.0*n);//这个连续乘积不会出现在根号n之后 int max_conse = 0;LL max_begin = 0;for(int i=2;i<=sqr;i++){if(n%i==0){int temp = 1;int len;for(int j=i;n%temp==0;j++){//2*3*4temp *= j;len = j-i;}      if(len>max_conse){max_conse = len;max_begin = i;}}}if(max_conse==0){printf("1\n");printf("%lld\n",n);return 0;} printf("%d\n",max_conse);for(int i=max_begin;i<max_begin+max_conse;i++){printf("%d",i);if(i!=max_begin+max_conse-1)printf("*");}return 0;
}

AC代码2

#include<cstdio>
#include<iostream>
#include<set>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<queue>
#include<string>using namespace std;const int maxn = 2000;typedef long long ll;int n;int getConFac(int n,int f){int num = 0;for(int i=f;i<=n;i++){if(n%i==0){n /= i;num ++;}else break;}return num;
} int main(){cin>>n;int maxNum = 0;int maxBF;//begin factorfor(int i=2;i<=sqrt(n);i++){if(n%i==0){int tempNum = getConFac(n,i);if(tempNum>maxNum){maxNum = tempNum;maxBF = i;}}}if(maxNum==0){printf("%d\n%d",1,n);return 0;}printf("%d\n",maxNum);for(int i=maxBF;i<maxBF+maxNum;i++){printf("%d",i);if(i!=maxBF+maxNum-1)printf("*");}return 0;
}

1096 Consecutive Factors相关推荐

  1. PAT甲级1096 Consecutive Factors :[C++题解]连续的因子、约数

    文章目录 题目分析 题目链接 题目分析 来源:acwing 题意重述:1个正整数N的因子中可能存在若干连续的数字.比如 N =630 ,N = 3 * 5 * 6 *7,这里连续的因子是5 *6 * ...

  2. 1096 Consecutive Factors (20 分)_24行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Among all the factors of a positive integer N, there may exist se ...

  3. 1096 Consecutive Factors (20 分)【难度: 一般 / 爆搜 数论】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805370650738688 注意测试点1: 72=2*3*3*4 我这里 ...

  4. 【PAT甲级 排序】1096 Consecutive Factors (20 分) C++ 全部AC

    题目 难倒是不难,暴力破解即可.要注意的就是开longlong,以及开方时,不要丢失临界值,还有如果子序列长度为0的话,输出num本身(因为计算的时候不考虑1这个因数). 一开始想出来一种O(n)的算 ...

  5. Consecutive Factors (20)

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

  6. PAT1096 Consecutive Factors (20)(逻辑)

    题意: 一个正整数N的因子中可能存在若干连续的数字.例如630可以分解为3*5*6*7,其中5.6.7就是3个连续的数字.给定任一正整数N,要求编写程序求出最长连续因子的个数,并输出最小的连续因子序列 ...

  7. PAT甲级题目翻译+答案 AcWing(数学)

    1059 Prime Factors (25 分) 题意 : 给一正整数,要求分解质因数 思路 : 使用is_first,来完成除了第一个质因数前都有*的效果 如果n=1,要特判 最后如果n>1 ...

  8. 【最新合集】PAT甲级最优题解(题解+解析+代码)

    以下每道题均是笔者多方对比后, 思考整理得到的最优代码,欢迎交流! 共同成长哇.可以和博主比拼一下谁刷的更快~ 欢迎收藏.欢迎来玩儿 PAT题解目录 题号 标题 题解 分类 使用算法 1001 A+B ...

  9. PAT (Advanced Level) Practice 题解代码 - II (1051-1100)

    PAT PAT (Advanced Level) Practice - II(1051-1100) -------------------------------------------------- ...

最新文章

  1. 查看依赖树_Python中的依赖关系处理
  2. 《UNIXLinux程序设计教程》一第2章-2.0 标准输入输出
  3. OpenCASCADE绘制测试线束:布尔运算命令之处理多个参数的通用命令
  4. 第二讲 数学模型方法
  5. 一些与HTML相关名词的简介
  6. Android 8.0 学习(26)---Android 8.0 SystemUI(一)
  7. android布局边缘加深,Android布局属性详解
  8. Configuring SharePoint 2010 and ADFS v2 End to End-摘自网络
  9. 被问到最多的淘口令API调用方法
  10. 【C语言笔记】【宏定义系列】 判断是否2的n次幂对齐
  11. 码云的注册与使用,很简单
  12. 怎么在电脑设置html,电脑怎么定时开机
  13. 《刻意练习》读书心得 驳斥1万小时定律、有目的的练习、自我实现的预言、走出舒适区
  14. mqtt简介及在web端的应用(接入阿里iot)
  15. vue项目,解决IE浏览器报Promise未定义的错误
  16. java inputstream read_Java学习之输入输出流
  17. 亲测3种个人在线网站建设的方法
  18. Cesium实战记录(八)三维风场+风速热力图(水平+垂直)
  19. Arduino测试一块5路带自锁开关输入模块
  20. 微软2018年重组背后,扒一扒受影响的人与事

热门文章

  1. 4 OC 中的内存分配以及内存对齐
  2. 09-dispatch_source
  3. 04-dispatch_group
  4. canvas.width和canvas.style.width区别以及应用
  5. php的匿名函数和闭包函数
  6. 如何查看Linq to SQL运行时,实际执行的Sql语句
  7. 当你学了现在的忘了前面的
  8. 为TextMate扩展全屏功能
  9. 解决Swift中present(uiImagePickerController,animated: true,completion: nil)闪退的问题
  10. mongodb使用常用语法,持续更新