1. Member Join Date
Feb 2008
Posts
9
Rep Power
0

## Math Related Problem

I'm trying to solve this problem
An irrational decimal fraction is created by concatenating the positive integers:

0.123456789101112131415161718192021...

It can be seen that the 12th digit of the fractional part is 1.

If dn represents the nth digit of the fractional part, find the value of the following expression.

d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000
Here is my code
Java Code:
```public class Test
{
public static void main(String[] args)
{
String strNbr="";
for(long i=1;i<1000000;i++)
strNbr= strNbr + i;
//Find the digits
int d1=1,d10,d100,d1000,d10000,d100000,d1000000;
int product=0;
d10=Integer.parseInt(strNbr.substring(9, 10));
d100=Integer.parseInt(strNbr.substring(99, 100));
d1000=Integer.parseInt(strNbr.substring(999, 1000));
d10000=Integer.parseInt(strNbr.substring(9999, 10000));
d100000=Integer.parseInt(strNbr.substring(99999, 100000));
d1000000=Integer.parseInt(strNbr.substring(999999, 1000000));
product = d1 * d10 * d100 * d1000 * d10000 * d100000 * d1000000;
System.out.println(product);
}
}```
I waited about 40 mins and the code showed no output :ehh:
I know the loop is so long and there must be a better method to do this, but I cant think of a better method than using a string to store the number, since using a integer or double would lead to an extremely large number and would be very hard to locate d10-d100-d1000....

so what do you think I should do to solve this problem?  Reply With Quote

2. ## d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000
Using the properties of numbers we can write this
d1 * d1 * d1 * d1 * d1 * d1 * d1 * Math.pow(10, 1000000000000000000000)
Java Code:
```public class Test {
public static void main(String[] args) {
// d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000
int terms = 7;
int n = 1*10+1;
long value = n;
long powersOfTen = 0;
for(int i = 1; i < terms; i++) {
value *= n;
for(int j = 0; j < i; j++)
powersOfTen += 1;
}
System.out.printf("value = %d * powersOfTen = %d%n" +
"expression evaluates to %d * 10^%d%n",
value, powersOfTen, value, powersOfTen);
System.out.printf("value should = %d  " +
"powersOfTen should = %d%n",
(long)Math.pow(n, 7), 6+5+4+3+2+1);

}
}```  Reply With Quote

3. Member Join Date
Feb 2008
Posts
9
Rep Power
0

## no no no
you got it all wrong
d1 ... d1000000.... are variable names
d1 is 1
the others are numbers between 0 and 9
the value you provided is wrong...  Reply With Quote

4. Member Join Date
Feb 2008
Posts
9
Rep Power
0

## ok here's how i solved it..
this is not a good way but it solved it
i looped till 100000 (a missing zero) which will not take so long to end, got the numbers d1,d10....d100000
so I still have d1000000 to find
since d1000000 is between 0 and 9
I tried all the numbers and found out that 210 is the correct answer  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•