1096 Consecutive Factors

// 因为N被连续整数 5*6*7整除的结果是3,而3只是相对于连续整数的产物,说明重点是找出连续整数,。
//所以大致题意就是给出一个N,找出一段连续整数,使得N被整除。
//观察样例给出的答案发现,N不会被除自身以外大于sqrt(N)的数整除。
//可以用两个for循环暴力枚举。

#include"iostream"
#include"cmath"

int main() {
    long long  N;
    scanf("%lld",&N);
    long long t = (long long)sqrt(N*1.0),MAX = -1,start = -1;//记录连续序列的最大长度;
    for(long long i = 2; i <=t; ++i) {
        long long temp = 1;
        for(long long j = i; j<=t; ++j) {
            temp*=j;//获取当前连续整数的乘积
            if(N % temp == 0) {
                if(MAX < j-i+1) {
                    MAX = j-i+1;
                    start = i;
                }
            } else break;
        }
    }
    if(MAX == -1) printf("1\n%lld",N);//如果是素数,那么输出N本身
    else {
        printf("%lld\n",MAX);
        for(long long i = 0; i < MAX; ++i) {
            printf("%lld",start+i);
            if(i < MAX - 1)
                printf("*");
        }
    }
    return 0;
}

原文地址:https://www.cnblogs.com/keep23456/p/12300998.html

时间: 2024-10-28 22:10:19

1096 Consecutive Factors的相关文章

1096. Consecutive Factors (20)——PAT (Advanced Level) Practise

题目信息 1096. Consecutive Factors (20) 时间限制400 ms 内存限制65536 kB 代码长度限制16000 B Among all the factors of a positive integer N, there may exist several consecutive numbers. For example, 630 can be factored as 3*5*6*7, where 5, 6, and 7 are the three consecu

PAT 1096. Consecutive Factors (20)

1096. Consecutive Factors (20) Among all the factors of a positive integer N, there may exist several consecutive numbers. For example, 630 can be factored as 3*5*6*7, where 5, 6, and 7 are the three consecutive numbers. Now given any positive N, you

PAT甲级——1096 Consecutive Factors (数学题)

本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/91349859 1096 Consecutive Factors (20 分) Among all the factors of a positive integer N, there may exist several consecutive numbers. For example, 630 can be factored as 3×5×6×7, where

1096. Consecutive Factors (20)

Among all the factors of a positive integer N, there may exist several consecutive numbers. For example, 630 can be factored as 3*5*6*7, where 5, 6, and 7 are the three consecutive numbers. Now given any positive N, you are supposed to find the maxim

PAT 1096. Consecutive Factors

Among all the factors of a positive integer N, there may exist several consecutive numbers. For example, 630 can be factored as 356*7, where 5, 6, and 7 are the three consecutive numbers. Now given any positive N, you are supposed to find the maximum

PAT 甲级 1096 Consecutive Factors

https://pintia.cn/problem-sets/994805342720868352/problems/994805370650738688 Among all the factors of a positive integer N, there may exist several consecutive numbers. For example, 630 can be factored as 3×5×6×7, where 5, 6, and 7 are the three con

PAT Advanced 1096 Consecutive Factors (20分)

Among all the factors of a positive integer N, there may exist several consecutive numbers. For example, 630 can be factored as 3×5×6×7, where 5, 6, and 7 are the three consecutive numbers. Now given any positive N, you are supposed to find the maxim

PAT (Advanced Level) 1096. Consecutive Factors (20)

如果是素数直接输出1与素数,否则枚举长度和起始数即可. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; long long n; bool prime(

PAT甲题题解-1096. Consecutive Factors(20)-(枚举)

题意:一个正整数n可以分解成一系列因子的乘积,其中会存在连续的因子相乘,如630=3*5*6*7,5*6*7即为连续的因子.给定n,让你求最大的连续因子个数,并且输出其中最小的连续序列. 比如一个数可以分解2*3*4*6*7*8,最大的连续个数为3,因为存在两个,输出最小的那个即2*3*4. 首先,一个数如果是合数,那么它的因子必定不会超过sqrt(n)或者sqrt(n)+1.如果为质数,那么只可能为自己,因为题目说了不包括1. 我们先将2~sqrt(n)+1中为n的因子存到factor数组中,