import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.LinkedList;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer("");
int[]idnum=new int[30240];
for(int i=98765,j=0;i>1233;i--){
boolean[]arr=new boolean[10];
if(i<10000)
arr[0]=true;
int temp=i;
boolean flag=true;
while(temp>0){
int index=temp%10;
if(arr[index]){
flag=false;
break;
}
arr[index]=true;
temp/=10;
}
if(flag){
idnum[j]=i;
j++;
}
}
LinkedList<String>[] list=new LinkedList[80];
for(int i=0;i<80;i++){
list[i]=new LinkedList<String>();
}
Arrays.sort(idnum);
for(int i=3024;i<idnum.length;i++){
int tempX=idnum[i];
for(int j=0;j<i;j++){
int tempY=idnum[j];
if(idnum[i]%idnum[j]==0 && checkIdent(idnum[i],idnum[j])){
int div=idnum[i]/idnum[j];
if(div>79){
break;
}else{
if(idnum[j]<10000){
list[div].add(idnum[i]+" / 0"+idnum[j]);
}else{
list[div].add(idnum[i]+" / "+idnum[j]);
}
}
}
}
}
boolean first =true;
while(true){
int x=Integer.parseInt(br.readLine());
if(x==0){
break;
}
if(!first){
sb.append("\n");
}
first=false;
if(!list[x].isEmpty()){
for(int i=0;i<list[x].size();i++){
sb.append(list[x].get(i)).append(" = ").append(x).append("\n");
}
}else{
sb.append("There are no solutions for ").append(x).append(".\n");
}
}
System.out.print(sb);
}
static boolean checkIdent(int x,int y){
boolean[] arr=new boolean[10];
if(x<10000)
arr[0]=true;
int temp=x;
while(temp>0){
int rem=temp%10;
arr[rem]=true;
temp/=10;
}
temp=y;
if(y<10000){
if(arr[0])
return false;
}
while(temp>0){
int rem=temp%10;
if(arr[rem]){
return false;
}
temp/=10;
}
return true;
}
}
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.LinkedList;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer("");
int[]idnum=new int[30240];
for(int i=98765,j=0;i>1233;i--){
boolean[]arr=new boolean[10];
if(i<10000)
arr[0]=true;
int temp=i;
boolean flag=true;
while(temp>0){
int index=temp%10;
if(arr[index]){
flag=false;
break;
}
arr[index]=true;
temp/=10;
}
if(flag){
idnum[j]=i;
j++;
}
}
LinkedList<String>[] list=new LinkedList[80];
for(int i=0;i<80;i++){
list[i]=new LinkedList<String>();
}
Arrays.sort(idnum);
for(int i=3024;i<idnum.length;i++){
int tempX=idnum[i];
for(int j=0;j<i;j++){
int tempY=idnum[j];
if(idnum[i]%idnum[j]==0 && checkIdent(idnum[i],idnum[j])){
int div=idnum[i]/idnum[j];
if(div>79){
break;
}else{
if(idnum[j]<10000){
list[div].add(idnum[i]+" / 0"+idnum[j]);
}else{
list[div].add(idnum[i]+" / "+idnum[j]);
}
}
}
}
}
boolean first =true;
while(true){
int x=Integer.parseInt(br.readLine());
if(x==0){
break;
}
if(!first){
sb.append("\n");
}
first=false;
if(!list[x].isEmpty()){
for(int i=0;i<list[x].size();i++){
sb.append(list[x].get(i)).append(" = ").append(x).append("\n");
}
}else{
sb.append("There are no solutions for ").append(x).append(".\n");
}
}
System.out.print(sb);
}
static boolean checkIdent(int x,int y){
boolean[] arr=new boolean[10];
if(x<10000)
arr[0]=true;
int temp=x;
while(temp>0){
int rem=temp%10;
arr[rem]=true;
temp/=10;
}
temp=y;
if(y<10000){
if(arr[0])
return false;
}
while(temp>0){
int rem=temp%10;
if(arr[rem]){
return false;
}
temp/=10;
}
return true;
}
}
No comments:
Post a Comment