题意:

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

trick:

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

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

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int ans[][];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n;
cin>>n;
long long tamp=;
int num=;
int cnt=;
int mx=;
int pos=;
for(long long j=;j*j<=n;++j){
tamp=n;
for(long long i=j;i*i<=n;++i)
if(tamp%i==){
tamp/=i;
ans[num][++cnt]=i;
}
else
break;
if(cnt>mx){
mx=cnt;
pos=num;
}
++num;
cnt=;
}
if(!mx){
cout<<"1\n"<<n;
return ;
}
else{
cout<<mx<<"\n";
for(int i=;i<=mx;++i){
cout<<ans[pos][i];
if(i<mx)
cout<<"*";
}
}
return ;
}

【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. VNCserver 安装 及 oracle过程总结

    一.安装桌面系统 1.命令   yum grouplist ---列举系统中以组安装的包(组安装的包会包括很多,组安装一下就就可以安装很多附在的包.) 2.  yum groupinstall &qu ...

  2. JS定义类的六种方式详解

    转载自: http://www.jb51.net/article/84089.htm 在前端开发中,经常需要定义JS类.那么在JavaScript中,定义类的方式有几种,分别是什么呢?本文就JS定义类 ...

  3. js面向对象的程序设计 --- 中篇(创建对象) 之 原型模式

    ·原型模式 我们创建的每一个函数都由一个prototype(原型)属性,这个属性是一个指针,指向一个对象,而这个对象的用途是包含可以由特定类型的所有 实例共享的属性和方法. 如果按照字面意思来理解,那 ...

  4. rancher三节点k8s集群部署例子

    rancher三节点k8s集群部署例子 待办 https://rorschachchan.github.io/2019/07/25/使用Rancher2-1部署k8s/

  5. [Linux] Ubuntu18.04 安装之后配置过程

    前言  最终还是安装了Ubuntu 虽然一开始想用Deepin 但是死活安装不上,我也很绝望(引导一直找不到 恢复BIOS默认设置也还是不行 所以 有些绝望啊....)  所以 为了让以后的我不再那么 ...

  6. winform学习(2)窗体属性

    窗体也属于控件(controls) 主窗体:在Main函数中创建的窗体,当关闭主窗体时,整个程序也就关闭了. 如何打开控件属性面板: ①在该控件上单击鼠标右键--属性. ②选中该控件,按F4 窗体常用 ...

  7. MyBatis(4)——配置文件优化

    配置文件优化 执行流程:读取配置流程->sqlSessionFactory->sqlSession(连接.读取sql并执行相应操作.关闭) a)配置优化:通过中文参考指南的说明可知-> ...

  8. static的使用总结

    全局静态变量 全局变量前加上关键字static,全局变量就定义成一个全局静态变量.,全局静态变量存储在静态存储区,在整个程序运行期间一直存在.全局静态变量在程序运行之前就存在. 初始化:未经初始化的全 ...

  9. AndroidStudio3.3+OpenCV开发环境搭建

    创建一个Android Studio普通项目 导入module 选择 File → New → Import Module 选择解压好的opencv-android-sdk下的sdk下的java,点O ...

  10. nfs 动态文件挂载读写权限设置

    nfs 动态文件挂载读写权限设置 待办 ll 命令查看文件夹权限 参考设置共享文件夹https://www.linuxidc.com/Linux/2018-11/155331.htm