[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

YES IT'S 9867312



> Based on your assumptions that no 5 and no 0 digits included in X, I found
> another number that is bigger than yours. It also satisfies the
> conditions of problems. That is 9867312. This number is divisable for
> every digits included such as 9,8,7,6,3,2, and 1.

YESSSSS.  I've just returned to fix it, but it a little late :(((  Thank
you ;-)

> 9) 1*2*3*6*7*8*9 = 18144

I'm terrible wrong here. We don't need 2 and 6 in the multiplication.

9) let it be 3 * 7 * 8 * 9 = 1512

10) We must check up down the numbers those have the form (n * 1512)
in the range (>10000000 and < 100000) until get the first valid
number.  That number is 9867312 as you showed, please change my
program below.

> I don't know what is the right X number for this problem because the
> unclear assumption of every digits (whether these digits composed X or
> every possible digits?)

I don't understand well what you meant.  I think the problem is clear
enough, and we have the right answer now, and Mr. Toan will be happy :))
Thank you again.  Do you agree to share credit to solve this problem
with me? :)

Cheers,
d~

----------------------------cut here-----------------------------------
#include <stdio.h>

#define MUL (3 * 7 * 8 * 9)		/* change is here */
#define MAX ((10000000 / MUL) * MUL)
#define MIN ((1000000 / MUL + 1) * MUL)

int a[7];

ten_power(int n)
{
     int i;
     int t;

     t = 1;
     for (i = 0; i < n; i++)
	  t = t * 10;
     return t;
}

digit(int n, int p)
{
     n = n / ten_power(p);
     return n % 10;
}

distinctive(int n)
{
     int i;

     for (i = 0; i < 7; i++)
	  a[i] = 0;

     for (i = 0; i < 7; i++) {
	  int d;
	  int j;

	  d = digit(n, i);
	  if (d >= 1 && d <= 3) {
	       j = d - 1;
	       a[j]++;
	  } else if (d >= 6) {
	       j = d - 3;
	       a[j]++;
	  } else
	       return 0;

	  if (a[j] > 1)
	       return 0;
     }
     return 1;
}

main()
{
     int n;

     n = MAX;
     while (n >= MIN) {
	  if (distinctive(n)) {
	       printf("%d\n", n);
	       exit(0);
	  }
	  n -= MUL;
     }
     printf("no solution\n");
     exit(0);
}

-------------------------------cut here-------------------------------