pe148

一個結論:

設f(n)表示第n行的不能被7整數的數的個數,(從第0行開始算)

n表示爲7進制,則

f(n) =( 各位數字+1 )的乘積

 

 

f(15): 15(10) = 21(7)

f(15) = (2+1)(1+1) = 6

 

public class PE148 {
    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        long r = 0;
        for (int i = 0; i < 10_0000_0000; i++) {
            r += count(i);
        }
        System.out.println(r);
        long end = System.currentTimeMillis();
        System.out.println((end - start) + "ms");

    }

    static long count(long n) {
        long result = 1;
        while (n > 0) {
            result *= (n % 7) + 1;
            n /= 7;
        }
        return result;
    }

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章