Forked from brunoperezm/Problema_OMA_3_Intercolegial.java
Created
March 21, 2020 19:14
-
-
Save dan-dm/25cc69345fab4ba57ed2d03196b1b2fd to your computer and use it in GitHub Desktop.
¿Cuántos números formados exclusivamente por los dígitos 3 y 7, y divisibles por 3 y por 7, son menores a 100000?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Problema_OMA_3 { | |
/** | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
/* | |
a) ¿Cuántos números formados exclusivamente por los dígitos 3 y 7, y divisibles por 3 y por 7, son menores a 100000? | |
b) ¿Cuántos números formados exclusivamente por los dígitos 3 y 7, y divisibles por 3 y por 7, son menores a 100000000?*/ | |
int[] ts = new int[6]; | |
boolean a_corrio_1vez = false; | |
boolean b_corrio_1vez = false; | |
boolean c_corrio_1vez = false; | |
boolean d_corrio_1vez = false; | |
boolean e_corrio_1vez = false; | |
//boolean f_corrio_1vez = false; | |
int contador = 0; | |
for (int a=0 ; a<= 4; ) { | |
if (a_corrio_1vez) {a+=3;} | |
if (a == 0) {a_corrio_1vez = true;} | |
for (int b = 0; b<= 4; ) { | |
if (b_corrio_1vez) {b+=3;} | |
if (b == 0) {b_corrio_1vez = true;} | |
for (int c = 0; c<= 4; ) { | |
if (c_corrio_1vez) {c+=3;} | |
if (c == 0) {c_corrio_1vez = true;} | |
for (int d = 0; d<= 4; ) { | |
if (d_corrio_1vez) {d+=3;} | |
if (d == 0) {d_corrio_1vez = true;} | |
for (int e = 0; e<= 4; ) { | |
if (e_corrio_1vez) {e+=3;} | |
if (e == 0) {e_corrio_1vez = true;} | |
for (int f = 0; f<= 7; f+=3 ) { | |
if (f == 0) {f=3;} | |
//if (f_corrio_1vez) {f+=3;} | |
int A = (a==6) ? 7 : a, | |
B = (b==6) ? 7 : b, | |
C = (c==6) ? 7 : c, | |
D = (d==6) ? 7 : d, | |
E = (e==6) ? 7 : e, | |
F = (f==6) ? 7 : f; | |
ts[0] = A; | |
ts[1] = B; | |
ts[2] = C; | |
ts[3] = D; | |
ts[4] = E; | |
ts[5] = F; | |
int numero_total = 0; | |
for (int i=0; i<ts.length; i++ ) { | |
numero_total += ts[i]*Math.pow(10,(ts.length-i)); | |
} | |
numero_total /= 10; | |
if (numero_total%3 == 0 && numero_total%7==0 ) { | |
contador++; | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
System.out.println(contador); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment