• PAT 1096 Consecutive Factors[难]


    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 maximum number of consecutive factors, and list the smallest sequence of the consecutive factors.

    Input Specification:

    Each input file contains one test case, which gives the integer N (1<N<231​​).

    Output Specification:

    For each test case, print in the first line the maximum number of consecutive factors. Then in the second line, print the smallest sequence of the consecutive factors in the format factor[1]*factor[2]*...*factor[k], where the factors are listed in increasing order, and 1 is NOT included.

    Sample Input:

    630
    

    Sample Output:

    3
    5*6*7

     题目大意:给出数N,找出其最长连续因子,因子要从小选起。

    //哇好难,越做越难,,,

    #include <iostream>
    #include <vector>
    #include<math.h>
    using namespace std;
    
    int main()
    {
       int n;
       cin>>n;
       int m=sqrt(n);
       int maxl=0,tp=0,bg=0;
       vector<int> vt;
       for(int i=2;i<=m;i++){
            int t=n;//这个i表示从哪个地方开始。
            if(n%i==0){
                tp++;
                t/=i;
                if(tp>maxl){
                    maxl=tp;
                    bg=i;//就是这个开始的时候。但是你得能整除才可以。哇这个好难。
                }
            }else{
                tp=0;
            }
       }
        cout<<maxl<<'
    ';
        for(int i=bg;i<maxl+tp;i++){
            cout<<i;
            if(i!=maxl+tp-1)
                cout<<"*";
        }
       return 0;
    }

    //写不下去了,要考虑好多问题啊。 

  • 相关阅读:
    零拷贝
    RxJava2源码解析
    一次博客崩溃日志分析
    Spring循环依赖的解决
    解决网络卡顿问题
    软工第一次作业
    3月26-27号训练笔记
    Codeforces Round #708 (Div. 2)题解A,B,C1,C2,E1,E2
    求出所有LIS的可行起点
    2020小米邀请赛决赛补题G,I,J(三DP)
  • 原文地址:https://www.cnblogs.com/BlueBlueSea/p/9953447.html
Copyright © 2020-2023  润新知