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