题意:

输入一个int范围内的正整数,输出它最多可以被分解为多少个连续的因子并输出这些因子以*连接。

trick:

测试点5包含N本身是一个素数的数据,此时应当输出1并把N输出。

测试点5包含一个2e9以上的int整数,此时最好把n当作long long 否则以下代码会运行超时。

AAAAAccepted code:

  1. #define HAVE_STRUCT_TIMESPEC
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. int ans[][];
  5. int main(){
  6. ios::sync_with_stdio(false);
  7. cin.tie(NULL);
  8. cout.tie(NULL);
  9. long long n;
  10. cin>>n;
  11. long long tamp=;
  12. int num=;
  13. int cnt=;
  14. int mx=;
  15. int pos=;
  16. for(long long j=;j*j<=n;++j){
  17. tamp=n;
  18. for(long long i=j;i*i<=n;++i)
  19. if(tamp%i==){
  20. tamp/=i;
  21. ans[num][++cnt]=i;
  22. }
  23. else
  24. break;
  25. if(cnt>mx){
  26. mx=cnt;
  27. pos=num;
  28. }
  29. ++num;
  30. cnt=;
  31. }
  32. if(!mx){
  33. cout<<"1\n"<<n;
  34. return ;
  35. }
  36. else{
  37. cout<<mx<<"\n";
  38. for(int i=;i<=mx;++i){
  39. cout<<ans[pos][i];
  40. if(i<mx)
  41. cout<<"*";
  42. }
  43. }
  44. return ;
  45. }

【PAT甲级】1096 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 (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 ...

  5. PAT甲级——A1096 Consecutive Factors【20】

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

  6. PAT 甲级 1035 Password (20 分)

    1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...

  7. PAT甲级——1152.Google Recruitment (20分)

    1152 Google Recruitment (20分) In July 2004, Google posted on a giant billboard along Highway 101 in ...

  8. 1096. Consecutive Factors (20)

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

  9. PAT 甲级 1073 Scientific Notation (20 分) (根据科学计数法写出数)

    1073 Scientific Notation (20 分)   Scientific notation is the way that scientists easily handle very ...

随机推荐

  1. Win系统如何修改远程桌面端口3389

    Win系统如何修改远程桌面端口3389: https://jingyan.baidu.com/article/ce43664928d5293773afd39b.html window10远程桌面连接: ...

  2. NAND FLASH驱动框架以及程序实现

    1.NAND FLASH的硬件连接: 实验用的NAND FLASH芯片为K9F2G08U0C,它是三星公司的存储芯片,它的大小为256M.它的接线图如下所示: 它的每个引脚的分别为LDATA0-LDA ...

  3. windows10中docker nginx开启 但页面访问不了

    Windows下对docker端口进行映射,但是当你在主机的浏览器中,打开localhost:port无法访问对应的服务. docker是运行在Linux上的,在Windows中运行docker,实际 ...

  4. RFC3984: RTP Payload Format for H.264 Video(中文版)

    转载地址:https://blog.csdn.net/h514434485/article/details/51010950 官方文档,中文版本地址:http://www.rosoo.net/File ...

  5. POJ 3368 (ST表)

    链接:http://poj.org/problem?id=3368 题意:给出n个连续单调不递减数,q次询问,每次询问区间(L,R)出现频率最多的数,问出现了多少次 思路:因为n个数是单调不递减的,所 ...

  6. 常用的 19 条 MySQL 优化

    一.EXPLAIN 做MySQL优化,我们要善用 EXPLAIN 查看SQL执行计划. 下面来个简单的示例,标注(1,2,3,4,5)我们要重点关注的数据 type列,连接类型.一个好的sql语句至少 ...

  7. MVC HTML辅助方法

    HTML辅助方法(HTML Helper)用来辅助产生HTML,在开发View的时候会面对许多HTML标签,处理这些HTML标签非常繁琐,为了降低View的复杂度,可以使用HTML辅助方法帮助你产生一 ...

  8. STM32F103之定时器学习记录

    /==============翻译STM32F103开发手册定时器部分========================/ 14 高级控制计时器(TIM1和TIM8) 14.1 TIM1和TIM8介绍 ...

  9. lua 排序table.sort()用法

    table.sort(),它要求要排序的目标table的必须是从1到n连续的,即中间不能有nil.当两个数相等的时候,比较函数一定要返回false. 探究性质,我们做个试验: 1)新建文件sortte ...

  10. windows7安装 npm和cnpm

    1.node.js下载地址: https://nodejs.org/en/download/ 我选择的安装路径是D:\files\nodejs 2.查看安装是否成功 3.创建文件夹 在D:\files ...