【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 ...
随机推荐
- Centos7部署jenkins
1. 下载rpm包: a) 下载地址:https://pkg.jenkins.io/redhat-stable/ b) 点选一个下载即可,例如点选:“jen ...
- js学习(精华帖)
js获取当前域名.Url.相对路径和参数以及指定参数 js获取当前url组成部分 jquery操作select(增加,删除,清空)
- ORA-04089: cannot create triggers on objects owned by SYS
04089 问题原因 因为你在以sys用户创建触发器,但oracle却不建议在sys用户下创建触发器.
- jsp中的javascript的$(document).ready( function() { $("#loginForm").validate()
转自:https://bbs.csdn.net/topics/392459787?list=71147533 下面是jsp页面中的JavaScript代码 $(document).ready( fun ...
- c++11 lambda简录
本文为转载,详情请观看原文连接 或许,Lambda 表达式算得上是 C++ 11 新增特性中最激动人心的一个.这个全新的特性听起来很深奥,但却是很多其他语言早已提供(比如 C#)或者即将提供(比如 J ...
- 2019-08-04 纪中NOIP模拟B组
T1 [JZOJ3403] 数列变换 题目描述 小X看到堆成山的数列作业十分头疼,希望聪明的你来帮帮他.考虑数列A=[A1,A2,...,An],定义变换f(A,k)=[A2,A3,...,Ak,A1 ...
- Intellij-Idea使用小细节
SpringMVC项目部署到tomcat中文乱码,tomcat的配置里面加上 -Dfile.encoding=UTF-8
- Docker - ubuntu 镜像安装网络工具
概述 给 ubuntu 镜像, 安装一些基本的网络工具 背景 尝试学习的时候, 需要检测网络的连通性 没有这些工具, 绕了不少弯路 工具们 ping ip a 环境 docker 18.09 ubun ...
- linux下grep分析apache日志的命令集合
https://my.oschina.net/hmc0316/blog/112004 实例:月份英文简写英文全称一月Jan.January二月Feb.February三月Mar.March四月Apr. ...
- 如何更改已经pushed的commit的注释信息(How to change the pushed commit message)
1, 修改最后一次注释(Modify the last comment message) git commit -amend 2,修改之前的注释 1)输入: git rebase -i HEAD~3 ...