Question 1125: The big integer factor C ++/Java

Source: Internet
Author: User

Question 1125: The big integer factor C ++/Java
Description:

The positive integer k is known to be 2 <= k <= 9, and a decimal non-negative integer c with a maximum length of 30 digits is given. All the k that can divide c is obtained.

Input:

Number of digits of some non-negative integers c and c <= 30
Each row has one c and is aborted when c =-1.
(Do not calculate-1 !)

Output:

Each result of c occupies one row.
1) if there is a k that satisfies c % k = 0, output all such k, separated by spaces in the middle, and there is no space behind the last k.
2) if no such k is available, "none" is output"

Sample input:
307213-1
Sample output:
2 3 5 62 3 4 6 8 9none
Tip:

Attention to Integer Overflow
Do not calculate-1


 

C ++ code:

 

# Include
   
    
# Include
    
     
# Include
     
      
Using namespace std; int main () {string s; while (cin> s & s! = "-1") {vector
      
       
Ivec; for (int n = 2; n <= 9; ++ n) {int index = 0; int temp; for (int I = 0; I
       
        
Java code:
        

 

 

import java.util.Scanner;public class Main{public static void main(String[] args){String str;int i,j,k;//int array[]=new int[100];Scanner cin=new Scanner(System.in);while(cin.hasNext()){str=cin.nextLine();boolean flag=false;char num[]=str.toCharArray();int len=num.length;j=0;if('-'==(num[0]))break;//System.exit(1);for(k=2;k<=9;k++){int temp;int index=0;for(i=0;i
         
          

 

Related Article

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.