### Exploring Pascal's triangle题号：148 难度： 50 中英对照

We can easily verify that none of the entries in the first seven rows of Pascal's triangle are divisible by 7:

 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1

However, if we check the first one hundred rows, we will find that only 2361 of the 5050 entries are not divisible by 7.

Find the number of entries which are not divisible by 7 in the first one billion (109) rows of Pascal's triangle.

### Code

public final class p148 {
public static void main(String[] args) {
long start=System.nanoTime();
String result = run();
long end=System.nanoTime();
System.out.println(result);
System.out.println( (end-start)/1000000 + "ms" );
}

static public String run() {
long n = 1000000000;
long c = 1;
long sum = 0;
while (n > 0) {
long k = 1;
long i = 0;
// checks divisibility by 7
while (k * 7 < n) {
k *= 7;
i += 1;
}
long m = n / k;
sum += c * m * (m + 1) / 2 * Math.pow(28, i);
n -= k * m;
c *= m + 1;
}
return sum+"";
}
}
2129970655314432
0ms