Java 1 AC
import java.math.BigInteger; import java.util.Scanner; public class Main { /* * 1125 2014年6月5日17:34:07 */ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { String num = scanner.next(); if (num.equals("-1")) { break; } BigInteger numBig = new BigInteger(num); boolean flag = false; StringBuffer sb = new StringBuffer(); int k = 2; while (k >= 2 && k <= 9) { if (numBig.mod(new BigInteger(k + "")).toString().equals("0")) { flag = true; sb.append(k + " "); } k++; } String result = (flag == true) ? sb.toString().trim() : "none"; System.out.println(result); } } } /************************************************************** Problem: 1125 User: wangzhenqing Language: Java Result: Accepted Time:1300 ms Memory:101376 kb ****************************************************************/Java 2 AC
import java.util.Scanner; public class Main { /* * 1125 2014年6月5日17:34:07 */ private static int len; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { String num = scanner.next(); if (num.equals("-1")) { break; } len = num.length(); boolean flag = false; StringBuffer sb = new StringBuffer(); int k = 2; while (k >= 2 && k <= 9) { if (isTrue(num, k)) { flag = true; sb.append(k + " "); } k++; } String result = (flag == true) ? sb.toString().trim() : "none"; System.out.println(result); } } private static boolean isTrue(String num, int k) { int num1 = 0; int num2 = 0; for(int i = 0; i < len; i++){ num1 = (num.charAt(i) - '0') + num2 * 10; num2 = num1 % k; } return num2 == 0 ? true : false; } } /************************************************************** Problem: 1125 User: wangzhenqing Language: Java Result: Accepted Time:790 ms Memory:40420 kb ****************************************************************/C++ 2 AC
#include <stdio.h> #include <string.h> const int maxLen = 32; char numArr[maxLen]; int len; bool isTrue(int k){ int num1 = 0; int num2 = 0; for(int i = 0; i < len; i++){ num1 = numArr[i] - '0' + num2 * 10; num2 = num1 % k; } return num2 == 0 ? true : false; } int main(){ while(scanf("%s", numArr) != EOF){ if(!strcmp(numArr, "-1")){ break; } len = strlen(numArr); bool flag = false; bool first = true; int k = 2; while(k >= 2 && k <= 9){ if(isTrue(k)){ flag = true; if(first){ printf("%d", k); first = false; }else{ printf(" %d", k); } } k++; } if(!flag){ printf("none\n"); }else{ printf("\n"); } } return 0; } /************************************************************** Problem: 1125 User: wangzhenqing Language: C++ Result: Accepted Time:30 ms Memory:1020 kb ****************************************************************/