L1-006 连续因子 (20分)
题意分析
题目中已经将意思说的很清楚了,就是输出一个数的最长连续因子的个数,并且输出是哪几个因子相乘。可以将题目从这两个角度进行分析:
- N为素数时,最长连续因子的个数为1,即它自己。
- N不为素数时,即N为合数时,暴力模拟即可,将连续的数进行累积,直到累积后的结果不能被N整除为止,这样就能够不断更新最长连续因子的个数,预保留第一个数,就可以在最终输出是能够直接输出这几个连续因子。
AC代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll;
typedef long double ld;
int N;
bool isprime(int n)
{
if(n == 2)
return true;
for(int i = 2; i <= sqrt(n); i++)
{
if(n % i == 0)
return false;
}
return true;
}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
scanf("%d", &N);
if(isprime(N))
{
cout << 1 << endl;
cout << N << endl;
}
else
{
int maxlen = 0, x;
for(int i = 2; i <= sqrt(N); i++)
{
if(N % i == 0)
{
int sx = i;
int j;
for(j = i + 1; j <= sqrt(N); j++)
{
sx *= j;
if(N % sx != 0)
break;
}
if(maxlen < j - i)
{
maxlen = j - i;
x = i;
}
}
}
cout << maxlen << endl;
for(int i = x; i <= x + maxlen - 1; i++)
{
if(i != x)
cout << "*";
cout << i;
}
cout << endl;
}
}
L1-006 连续因子 (20分)的更多相关文章
- L1-006 连续因子 (20 分) 模拟
一个正整数 N 的因子中可能存在若干连续的数字.例如 630 可以分解为 3×5×6×7,其中 5.6.7 就是 3 个连续的数字.给定任一正整数 N,要求编写程序求出最长连续因子的个数,并输出最小的 ...
- L1-006 连续因子(20)(思路+测试点分析)
L1-006 连续因子(20 分) 一个正整数 N 的因子中可能存在若干连续的数字.例如 630 可以分解为 3×5×6×7,其中 5.6.7 就是 3 个连续的数字.给定任一正整数 N,要求编写程序 ...
- L1-006. 连续因子
https://www.patest.cn/contests/gplt/L1-006 题目地址 在上面 一个正整数N的因子中可能存在若干连续的数字.例如630可以分解为3*5*6*7,其中5.6.7就 ...
- PTA 01-复杂度1 最大子列和问题 (20分)
题目地址 https://pta.patest.cn/pta/test/15/exam/4/question/709 5-1 最大子列和问题 (20分) 给定KK个整数组成的序列{ N_1N1 ...
- PAT-2019年冬季考试-甲级 7-1 Good in C (20分)
7-1 Good in C (20分) When your interviewer asks you to write "Hello World" using C, can y ...
- PAT 甲级 1050 String Subtraction (20 分) (简单送分,getline(cin,s)的使用)
1050 String Subtraction (20 分) Given two strings S1 and S2, S=S1−S2 is defined to be t ...
- PAT (Advanced Level) Practice 1005 Spell It Right (20 分) 凌宸1642
PAT (Advanced Level) Practice 1005 Spell It Right (20 分) 凌宸1642 题目描述: Given a non-negative integer N ...
- PAT (Basic Level) Practice (中文)1078 字符串压缩与解压 (20 分) 凌宸1642
PAT (Basic Level) Practice (中文)1078 字符串压缩与解压 (20 分) 凌宸1642 题目描述: 文本压缩有很多种方法,这里我们只考虑最简单的一种:把由相同字符组成的一 ...
- PAT乙级:1094 谷歌的招聘 (20分)
PAT乙级:1094 谷歌的招聘 (20分) 题干 2004 年 7 月,谷歌在硅谷的 101 号公路边竖立了一块巨大的广告牌(如下图)用于招聘.内容超级简单,就是一个以 .com 结尾的网址,而前面 ...
随机推荐
- [转]SpringBoot整合Swagger2以及生产环境的安全问题处理
1.创建springboot项目 https://www.cnblogs.com/i-tao/p/8878562.html 这里我们使用多环境配置: application-dev.yml(开发环境) ...
- H3C PPP的特点
- jmeter登录配置
前言: jmeter, Apache下的测试工具, 常用来进行压测, 项目中, 接口通常都需要进行登录才能被调用, 直接调用将提示"登录失效", 下面介绍如何在jmeter中配置参 ...
- java 合并流(SequenceInputStream)
需要两个源文件,还有输出的目标文件 SequenceInputStream: 将两个文件的内容合并成一个文件 该类提供的方法: SequenceInputStream(InputStream s1, ...
- P1092 电子表格
题目描述 在流行的电子表格系统中(例如,在Excel中),使用如下计算方式来对列号进行计算. 第1列对应A,第2列对应B,--,第26列对应Z.然后使用两个大写英文字母来表示列:第27列对应AA,第2 ...
- CCPC2018 桂林 D "Bits Reverse"
传送门 题目描述 Now given two integers x and y, you can reverse every consecutive three bits ,,) means chan ...
- H3C H3C设备DNS功能实现
- linux 禁止单个中断
有时(但是很少!)一个驱动需要禁止一个特定中断线的中断递交. 内核提供了 3 个函数为 此目的, 所有都声明在 <asm/irq.h>. 这些函数是内核 API 的一部分, 因此我们描述它 ...
- vue-learning:18 - js - watch
watch watch可以监听data和computed中值的变化. watch在实例对象作用域中可以监听实例对象的数据,即var vm = new Vue(options)时作为配置对象属性传入.监 ...
- HDU - 6333 Problem B. Harvest of Apples (莫队)
There are nn apples on a tree, numbered from 11 to nn. Count the number of ways to pick at most mm a ...