[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
The NUMBER is 1687392
Pham Thi Thanh Hong <smm68490@ait.ac.th> wrote:
> Hi Tuan, & Trung
>
> Sorry for a wrong previous solution. This number is undivisable for 8. I
> have tried another way to get solution as follows:
>
> ---------------
> Solution
>
> Because, it is the largest seven - digit number and those digits are
> unique, so I can guest it is formed under a down trend as 9876543.
>
> Firstly, we have to find a smalleast number that is divisable for every
> digit. This must be 2520.
>
> The maximum number that is divisable for 2520 under 9876543 is 9875880.
> Because this number consists of triple 8, therefore, we must to find
> another one which under this value.
>
> By subtracting the amount of 2520 from the number of 9875880 till every
> digit of X is different each other, we get the result of 9843120.
>
> Thus, the expected number must be 9843120.
>
> Test it again, OK.
Hi Hong,
I think your number is not divisible to 0. No number can be.
This is mine (with a little help from my computer :))
1) There no 0, so 9 digits remain.
2) The least sinificant digit can't be odd number. If it is, the
number can not be divisible to 2, 4, 6 and 8 and we don't have enough
number. Because there no 0 and the least significant digit is event,
there no 5 in our number.
3) 8 number 1,2,3,4,6,7,8 and 9 remain.
4) If there no 9 in the number, 1+2+3+4+6+7+8 = 31, the number can not
be divisible to 3.
5) If number include 9. Because 1+2+3+4+6+7+8+9 = 40, there is only
one way to make the 7-digit number be divisible to 9 is excepting 4
from the set of digits.
8) So 7 digits 1,2,3,6,7,8,9 remain to used.
9) 1*2*3*6*7*8*9 = 18144
10) We must check out 496 numbers those have the form (n * 18144) in
the range (>=1016064 and <= 9997344) to get the valid and biggest
number. That number is 1687392, if the following program is bug-free
:)
d~
--cut here--------------------------------------------------------
#include <stdio.h>
#define MUL (2 * 3 * 6 * 7 * 8 * 9)
#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----------------------------------------------------------