Java Continuous Factor __java

Source: Internet
Author: User
l1-006. Continuous factor

There may be several consecutive digits in the factor of a positive integer n. For example, 630 can be decomposed into 3*5*6*7, where 5, 6, and 7 are 3 consecutive digits. Given any positive integer n, it is required to write a program to find the number of longest continuous factors and to output the smallest sequence of continuous factors.

Input Format:

Enter a positive integer N (1<n<231) on one line.

output Format:

First, the number of the longest continuous factor is output in line 1th, then the smallest sequence of continuous factors is output in the 2nd row in the form of "factor 1* factor 2*......* K", in which the factor is output in ascending order, and 1 is not counted.

Input Sample:

630

Output Sample:

3

5*6*7

Analysis:

Assuming that N exists a sequence of continuous factors satisfying the order, the number of the sequence should be greater than or equal to 2, and the first factor of the sequence must be less than sqrt (n), and because 1 is not considered.

then the first factor of the desired factor sequence begins to circulate from 2 to sqrt (N).

The range of the positive integer N that the title requires is (1<n<231), 231 is 2 147 483 648, just between 12. (479 001 600) and 13. (6 227 020 800).

then the number of consecutive factors that can be measured n is up to 12. For Each loop, there may be a set of sequences to satisfy the order, and the length of the sequence can be from 2 to 12.

when you jump out of two loops, stating that n is prime, the length of the continuous factor is 1, and the sequence is n itself.

Code:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.