Problem:


Problem B: Square Coins

People in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Coins with values of all square numbers up to 289 (= 172), i.e., 1-credit coins, 4-credit coins, 9-credit coins, ..., and 289-credit coins, are available in Silverland.

There are four combinations of coins to pay ten credits:

ten 1-credit coins,

one 4-credit coin and six 1-credit coins,

two 4-credit coins and two 1-credit coins, and

one 9-credit coin and one 1-credit coin.

Your mission is to count the number of ways to pay a given amount using coins of Silverland.

Input

The input consists of lines each containing an integer meaning an amount to be paid, followed by a line containing a zero. You may assume that all the amounts are positive and less than 300.

Output

For each of the given amount, one line containing a single integer representing the number of combinations of coins should be output. No other characters should appear in the output.

Sample Input

2
10
30
0

Output for the Sample Input

1
4
27



Sample input:
2
10
30
0


Sample output:
1
4
27

Submission status: Accepted

Solution code:
# AOJ 1209: Square Coins
#Python3 2018.7.19 bal4u

N = 18
tbl = [i**2 for i in range(0, N)]
dp = [[0 for j in range(600)] for i in range(N)]
dp[0][0] = 1
for i in range(1, N):
    for n in range(300):
        dp[i][n] += dp[i-1][n]
        for j in range(tbl[i], 300, tbl[i]):
            dp[i][n+j] += dp[i-1][n]

while True:
    n = int(input())
    if n == 0: break
    print(dp[N-1][n])

Submission status: Accepted

Solution code:
# AOJ 1209: Square Coins
#Python3 2018.7.19 bal4u

dp = [1]*300
for i in range(2, 18):
    for j in range(i**2, 300): dp[j] += dp[j-i**2]

while True:
    n = int(input())
    if n == 0: break
    print(dp[n])

Submission status: Accepted

Solution code:
dp=[1]*301
for i in range(2,18):
    for j in range(i*i,301):dp[j]+=dp[j-i*i]
while 1:
    n=int(input())
    if n==0:break
    print(dp[n])

Submission status: Accepted

Solution code:
dp = [1] + [0]*300
for c in range(1,18):
	for i in range(301-c**2):
			dp[i+c**2] += dp[i]
while 1:
	n = input()
	if n == 0: break
	print dp[n]

Submission status: Accepted

Solution code:
# AOJ 1209: Square Coins
#Python3 2018.7.19 bal4u
 
dp = [1]*300
for i in range(2, 18):
    for j in range(i**2, 300): dp[j] += dp[j-i**2]
 
while True:
    n = int(input())
    if n == 0: break
    print(dp[n])

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
write = sys.stdout.write
dp = [0]*601
dp[0] = 1
V = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289]
for v in V:
    for k in range(300, -1, -1):
        x = dp[k]
        w = v
        while k+w <= 300:
            dp[k+w] += x
            w += v

while 1:
    N = int(readline())
    if not N:
        break
    write("%d\n" % dp[N])