Pascal Multiple

시간 제한1초메모리 제한1024 MB

요약
파스칼 삼각형의 처음 N+1개 행에서 이항계수가 K로 나누어떨어지는 항목의 개수를 센다.
난이도

쉬움10점 중 3점

유형
배열, 동적 계획법, 수학
정답자
아직 제출이 없습니다

문제

The (i,j)(i,j)th binomial coefficient, denoted C(i,j)C(i,j), is the (zero-indexed) jjth entry of the (zero-indexed) iith row in Pascal's triangle:

1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
...

where C(0,0)=1C(0,0) = 1 and the (i+1)(i+1)st row can be computed from the iith row using the recursion C(i+1,j)=C(i,j)+C(i,j−1),C(i+1, j) = C(i,j) + C(i, j-1), treating as 00 any out-of-bounds entries of the triangle on the right-hand side.

Given NN and KK, compute how many entries in the first N+1N+1 rows of Pascal's triangle are multiples of KK. To be precise: for how many pairs of indices (i,j)(i,j) with 0≤i≤N0\leq i\leq N and 0≤j≤i0 \leq j \leq i, is C(i,j)C(i,j) divisible by KK?

입력

The single line of input contains two positive integers NN (1≤N≤103)(1 \leq N \leq 10^3) and KK (1≤K≤N)(1 \leq K \leq N), with meaning as described above.

출력

Print the number of entries in the first N+1N+1 rows of Pascal's triangle that are divisible by KK.

예제2

  1. 예제 1

    입력
    5 3
    
    예상 출력
    3
    
  2. 예제 2

    입력
    1000 4
    
    예상 출력
    394315