62,614
社区成员
发帖
与我相关
我的任务
分享
public void test() {
int k = 2; //[2, 9]
String s1, s2;
int i, j, t;
boolean dup;
for (i=1234; i<100000/k; i++) {
s1 = String.valueOf(i);
j = i;
dup = false;
while (j > 0) {
if (s1.length()-s1.replaceAll(""+(j%10), "").length() > 1) {
dup = true;
break;
}
j /= 10;
}
if (dup) {continue;}
j = i * k;
s2 = String.valueOf(k);
t = j;
dup = false;
while (t > 0) {
if (s2.length()-s2.replaceAll(""+(t%10), "").length() > 1 ||
s1.contains(""+(t%10))) {
dup = true;
break;
}
t /= 10;
}
if (dup) {continue;}
System.out.printf("%d/%d,k=%d\n", i, j, k);
}
}
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class trick1 {
// 参数: n ---- EFGHI = n * ABCD
// 返回: 含ABCD的List
public static List<Integer> find(int n) {
List<Integer> list = new ArrayList<Integer>();
int i,j,k,l;
int x;
for (i=1; i<=9; i++) {
for (j=1; j<=9; j++) {
if (j==i) continue;
for (k=1; k<=9; k++) {
if (k==i||k==j) continue;
for (l=1; l<=9; l++) {
if (l==i||l==j||l==k) continue;
x = i*1000+j*100+k*10+l;
if (validate(x,n)) list.add(x);
}
}
}
}
return list;
}
public static boolean validate(int x, int n) {
int x2 = x*n, mod;
if (x2<10000 || x2>99999) return false;
String s = ""+x+x2;
if (s.indexOf("0")>=0) return false;
HashMap map = new HashMap();
for (int i=0; i<s.length(); i++)
map.put(s.charAt(i), null);
return map.size()==s.length();
}
//测试 (2倍,3倍)
public static void main(String[] args) {
int n;
List<Integer> result;
n = 2;
System.out.println("n=" + n);
result = find(n);
for (int i=0; i<result.size(); i++)
System.out.println(result.get(i) + " " + result.get(i)*n);
System.out.println();
n = 3;
System.out.println("n=" + n);
result = find(n);
for (int i=0; i<result.size(); i++)
System.out.println(result.get(i) + " " + result.get(i)*n);
System.out.println();
}
}
a = 5 #
e = 1 #
arr = [2, 3, 4, 6, 7, 8, 9]
for item in arr.permutation(7)
b, c, d, f, g, h, i = *item
if i % 2 == 0
m = 10000 + f * 1000 + g *100 + h * 10 + i
n = 5000 + b * 100 + c * 10 + d
if m / n * 2 == m
p item
end
end
end