【PAT甲级】1096 Consecutive Factors (20 分)
题意:
输入一个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 分)的更多相关文章
- PAT甲级——1096 Consecutive Factors (数学题)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/91349859 1096 Consecutive Factors ...
- PAT 甲级 1096 Consecutive Factors
https://pintia.cn/problem-sets/994805342720868352/problems/994805370650738688 Among all the factors ...
- PAT Advanced 1096 Consecutive Factors (20) [数学问题-因子分解 逻辑题]
题目 Among all the factors of a positive integer N, there may exist several consecutive numbers. For e ...
- 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 ...
- PAT甲级——A1096 Consecutive Factors【20】
Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam ...
- PAT 甲级 1035 Password (20 分)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...
- PAT甲级——1152.Google Recruitment (20分)
1152 Google Recruitment (20分) In July 2004, Google posted on a giant billboard along Highway 101 in ...
- 1096. Consecutive Factors (20)
Among all the factors of a positive integer N, there may exist several consecutive numbers. For exam ...
- PAT 甲级 1073 Scientific Notation (20 分) (根据科学计数法写出数)
1073 Scientific Notation (20 分) Scientific notation is the way that scientists easily handle very ...
随机推荐
- Win系统如何修改远程桌面端口3389
Win系统如何修改远程桌面端口3389: https://jingyan.baidu.com/article/ce43664928d5293773afd39b.html window10远程桌面连接: ...
- NAND FLASH驱动框架以及程序实现
1.NAND FLASH的硬件连接: 实验用的NAND FLASH芯片为K9F2G08U0C,它是三星公司的存储芯片,它的大小为256M.它的接线图如下所示: 它的每个引脚的分别为LDATA0-LDA ...
- windows10中docker nginx开启 但页面访问不了
Windows下对docker端口进行映射,但是当你在主机的浏览器中,打开localhost:port无法访问对应的服务. docker是运行在Linux上的,在Windows中运行docker,实际 ...
- RFC3984: RTP Payload Format for H.264 Video(中文版)
转载地址:https://blog.csdn.net/h514434485/article/details/51010950 官方文档,中文版本地址:http://www.rosoo.net/File ...
- POJ 3368 (ST表)
链接:http://poj.org/problem?id=3368 题意:给出n个连续单调不递减数,q次询问,每次询问区间(L,R)出现频率最多的数,问出现了多少次 思路:因为n个数是单调不递减的,所 ...
- 常用的 19 条 MySQL 优化
一.EXPLAIN 做MySQL优化,我们要善用 EXPLAIN 查看SQL执行计划. 下面来个简单的示例,标注(1,2,3,4,5)我们要重点关注的数据 type列,连接类型.一个好的sql语句至少 ...
- MVC HTML辅助方法
HTML辅助方法(HTML Helper)用来辅助产生HTML,在开发View的时候会面对许多HTML标签,处理这些HTML标签非常繁琐,为了降低View的复杂度,可以使用HTML辅助方法帮助你产生一 ...
- STM32F103之定时器学习记录
/==============翻译STM32F103开发手册定时器部分========================/ 14 高级控制计时器(TIM1和TIM8) 14.1 TIM1和TIM8介绍 ...
- lua 排序table.sort()用法
table.sort(),它要求要排序的目标table的必须是从1到n连续的,即中间不能有nil.当两个数相等的时候,比较函数一定要返回false. 探究性质,我们做个试验: 1)新建文件sortte ...
- windows7安装 npm和cnpm
1.node.js下载地址: https://nodejs.org/en/download/ 我选择的安装路径是D:\files\nodejs 2.查看安装是否成功 3.创建文件夹 在D:\files ...