Enter a positive integer n, return a minimum positive integer m (m at least 2 digits), so that M's product equals n, such as input 36, output 49, input 100, output 455, for some n does not exist such m, please return-1. _ Enter a positive integer n

Source: Internet
Author: User
Enter a positive integer n, return a minimum positive integer m (m at least 2 digits), so that M's product equals n, such as input 36, output 49, input 100, output 455, for some n does not exist such m, please return-1.
package hope20141002_01;
Import java.util.*;
public class Jingdong {public

 
	static void Main (string[] args) {
		//TODO auto-generated method stub
		System.out . println ("Please enter a positive integer:");
			int K=fun (getString ());
			System.out.println ("Output min positive integer:" +k);
	}
	public static Integer getString () {return
		integer.parseint (new Scanner (system.in)). nextline ());
	public static int Fun (int n1) {
		int n=n1; String k= "";
		if (n<=9) {return
			10+n;
		}
		for (int i=9;i>=2;) {
			if (n%i==0) {
				k+=i;
				n=n/i;
				Continue;
			} else
				i--;
		}
		int J=0;int n2=1;
		while (J<k.length ()) {
			N2=n2*integer.parseint (K.charat (j) + "");
			j + +;
		}
		if (n2!=n1) {
			return-1;
		}
		String temp= "";
		for (int i=k.length () -1;i>=0;i--) {
			Temp+=k.charat (i);
		}
		return Integer.parseint (temp);
	}


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.