题意分析

题目中已经将意思说的很清楚了,就是输出一个数的最长连续因子的个数,并且输出是哪几个因子相乘。可以将题目从这两个角度进行分析:

  • 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分)的更多相关文章

  1. L1-006 连续因子 (20 分) 模拟

    一个正整数 N 的因子中可能存在若干连续的数字.例如 630 可以分解为 3×5×6×7,其中 5.6.7 就是 3 个连续的数字.给定任一正整数 N,要求编写程序求出最长连续因子的个数,并输出最小的 ...

  2. L1-006 连续因子(20)(思路+测试点分析)

    L1-006 连续因子(20 分) 一个正整数 N 的因子中可能存在若干连续的数字.例如 630 可以分解为 3×5×6×7,其中 5.6.7 就是 3 个连续的数字.给定任一正整数 N,要求编写程序 ...

  3. L1-006. 连续因子

    https://www.patest.cn/contests/gplt/L1-006 题目地址 在上面 一个正整数N的因子中可能存在若干连续的数字.例如630可以分解为3*5*6*7,其中5.6.7就 ...

  4. PTA 01-复杂度1 最大子列和问题 (20分)

    题目地址 https://pta.patest.cn/pta/test/15/exam/4/question/709 5-1 最大子列和问题   (20分) 给定KK个整数组成的序列{ N_1N​1​ ...

  5. 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 ...

  6. PAT 甲级 1050 String Subtraction (20 分) (简单送分,getline(cin,s)的使用)

    1050 String Subtraction (20 分)   Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be t ...

  7. 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 ...

  8. PAT (Basic Level) Practice (中文)1078 字符串压缩与解压 (20 分) 凌宸1642

    PAT (Basic Level) Practice (中文)1078 字符串压缩与解压 (20 分) 凌宸1642 题目描述: 文本压缩有很多种方法,这里我们只考虑最简单的一种:把由相同字符组成的一 ...

  9. PAT乙级:1094 谷歌的招聘 (20分)

    PAT乙级:1094 谷歌的招聘 (20分) 题干 2004 年 7 月,谷歌在硅谷的 101 号公路边竖立了一块巨大的广告牌(如下图)用于招聘.内容超级简单,就是一个以 .com 结尾的网址,而前面 ...

随机推荐

  1. Capistrano:自动完成多台服务器上新版本的同步更新,包括数据库的改变

    https://baike.baidu.com/item/Capistrano/6844928?fr=aladdin   Capistrano是一种在多台服务器上运行脚本的开源工具,它主要用于部署we ...

  2. springmvc web.xml和application.xml配置详情(附:完整版pom.xml)

    web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="htt ...

  3. 【7003】&&【a203】合并多项式

    Time Limit: 3 second Memory Limit: 2 MB 问题描述      求两个一元多项式的和.输入多项式方式为:多项式项数.每项系数和指数,按指数从大到小的顺序输入.输出多 ...

  4. UVa 1627 - Team them up!——[0-1背包]

    Your task is to divide a number of persons into two teams, in such a way, that: everyone belongs to ...

  5. UVa 11134 - Fabled Rooks——[问题分解、贪心法]

    We would like to place n rooks, ≤ n ≤ , on a n × n board subject to the following restrictions • The ...

  6. java 事件监听机制组成

    事件源(组件) 事件(Event) 监听器(Listener) 事件处理(引发事件后处理方式) 事件监听机制流程图 务必记牢: 确定事件源(容器或组件) 通过事件源对象的addXXXListener( ...

  7. linux 存取 I/O 内存

    在一些平台上, 你可能逃过作为一个指针使用 ioremap 的返回值的惩罚. 这样的使用不 是可移植的, 并且, 更加地, 内核开发者已经努力来消除任何这样的使用. 使用 I/O 内 存的正确方式是通 ...

  8. vue脚手架搭项目 git push超时github网站打不开

    vue: 1.npm install vue-cli -g 全局安装脚手架 2.vue init webpack  name 新建项目 name为项目名称 react: 1..npm install  ...

  9. Spring、Spring Boot和TestNG测试指南 - 使用Spring Boot Testing工具

    Github地址 前面一个部分讲解了如何使用Spring Testing工具来测试Spring项目,现在我们讲解如何使用Spring Boot Testing工具来测试Spring Boot项目. 在 ...

  10. How to output the target message in dotnet build command line

    How can I output my target message when I using dotnet build in command line. I use command line to ...