【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 ...
随机推荐
- MyBatis使用步骤及原理
主要讲解MyBatis-基本使用步骤 回顾: MyBatis是一个数据持久层(ORM)框架.把实体 类和SQL语句之间建立了映射关系,是一种半自 动化的ORM实现.MyBATIS需要 ...
- CSS的布局之文档流,与行内/块级元素的延伸
文档流,即(position:stiatic),是html布局机制的默认状态. 文档流在排列的过程中,块级元素从上到下,行内元素,从左到右. ·块级元素 <div> <h系列> ...
- 线程同步器CountDownLatch
Java程序有的时候在主线程中会创建多个线程去执行任务,然后在主线程执行完毕之前,把所有线程的任务进行汇总,以前可以用线程的join方法,但是这个方法不够灵活,我们可以使用CountDownLatch ...
- SpringBoot整合WEB开发--(一)处理JSON返回数据
1.使用默认的json转换HttpessageConverter Json是目前主流的前后端数据传输方式,SpringMVC中使用消息转化器HttpMessageConverter对JSON的转换提供 ...
- 百度地图使用http ,https
通过判断http或https if($_SERVER['REQUEST_SCHEME']=='http'){ return true; }else{ return false; } https网站使用 ...
- Codeforces Round #598 (Div. 3) B Minimize the Permutation
B. Minimize the Permutation You are given a permutation of length nn. Recall that the permutation is ...
- MySQL数据库 | 数据表-查询命令详细记录
本篇专门记录数据库增删改查中最常用.花招最多的 查. [文章结构] 一.数据的准备 二.基本的查询功能 三.条件查询 四.查询排序 五.聚合函数 六.分组查询 七.分页查询 八.连接查询 九.子查询 ...
- 【Python】 基础语法
Python 语言与 Perl,C 和 Java 等语言有许多相似之处.但是,也存在一些差异. 第一个 Python 程序 欢迎,入坑! Python 标识符 在 Python 里,标识符由字母.数 ...
- HTML5学习(4)文本元素
使用VSCode编辑器,内置emmet插件. ctrl+/ 注释/取消注释 ctrl+enter 新起一行 ctrl+shift+enter 往上新起一行 h$*4>lorem10 <h1 ...
- [Note]后缀数组
后缀数组 代码 void rsort() { for (int i = 1; i <= m; ++i) tax[i] = 0; for (int i = 1; i <= n; ++i) + ...