public class Desen {
public static final int[][] TERMINA1 = {{1,1},{3,7},{9,9},{-1,-1}};
public static final int[][] TERMINA3 = {{1,3},{7,9},{-1,-1}};
public static final int[][] TERMINA7 = {{1,7},{3,9},{-1,-1}};
public static final int[][] TERMINA9 = {{1,9},{3,3},{7,7},{-1,-1}};
public static void main(String[] args) {
principal();
}
public static void principal() {
long n=8441081851627;
String result=recursiva(n, 0, 0, 0);
System.out.println(result==null? n + " es primo": n+ " es mulp de " + result);
}
public static String recursiva(long num, int pos, long xt, long yt) {
String str=null;
long numact=num-(xt*yt);
int[][]res=(pos==0) ? primera(numpos(numact,pos)) :comprueba(numpos(numact,pos),numpos(xt,0),numpos(yt,0));
for (int i=0; i<10 && res
public static final int[][] TERMINA1 = {{1,1},{3,7},{9,9},{-1,-1}};
public static final int[][] TERMINA3 = {{1,3},{7,9},{-1,-1}};
public static final int[][] TERMINA7 = {{1,7},{3,9},{-1,-1}};
public static final int[][] TERMINA9 = {{1,9},{3,3},{7,7},{-1,-1}};
public static void main(String[] args) {
principal();
}
public static void principal() {
long n=8441081851627;
String result=recursiva(n, 0, 0, 0);
System.out.println(result==null? n + " es primo": n+ " es mulp de " + result);
}
public static String recursiva(long num, int pos, long xt, long yt) {
String str=null;
long numact=num-(xt*yt);
int[][]res=(pos==0) ? primera(numpos(numact,pos)) :comprueba(numpos(numact,pos),numpos(xt,0),numpos(yt,0));
for (int i=0; i<10 && res
- >-1; i++) {
long x=xt+(long)(Math.pow(10, pos)*res- );
long y=yt+(long)(Math.pow(10, pos)*res[1]);
long z=x*y;
if (z < num && z > 0 && numpos(num-z, pos)==0)
str=recursiva(num, pos + 1, x, y);
else if (z==num && x>1 && y> 1)
return x+" y "+y;
if (str != null) return str;
}
return null;
}
public static int[][] primera (int x){
switch(x) {
case 1: return TERMINA1;
case 3: return TERMINA3;
case 7: return TERMINA7;
case 9: return TERMINA9;
};
return TERMINA1;
}
public static int numpos (long num, int pos) {
String sn=(num+"");
return Integer.parseInt(sn.substring(sn.length()-pos-1, sn.length()-pos));
}
public static int[][] comprueba (int num, int x, int y) {
int[][] resul=new int[10][2];
int m=0,n=0;
for (int i=0; i<10; i++)
for (int j=0; j<10; j++) {
if((x==-1 ? i*j : i*y+j*x)%10==num) {
boolean encontrado=false;
if (x==-1) {
for (int k=0; k<m && !encontrado; k++)
encontrado= (resul[k][0]==j && resul[k][1]==i);
}
if (!encontrado) {
resul[m][n++]=i;
resul[m++][n--]=j;
}
}
}
if(m<resul.length){
resul[m][0]=resul[m][1]=-1;
}
return resul;
}
}
- );