import java.util.Arrays;
/*
プログラミングのお題スレ Part15
//mevius.5ch.net/test/read.cgi/tech/1564310397/744
744 名前:デフォルトの名無しさん[sage] 投稿日:2019/10/11(金) 21:55:54.61 ID:zKaC3xv0
お題:0~9999の整数について数字和を求め、数字和の頻度を集計せよ
ocaml
//ideone.com/AjcGgp
c
//ideone.com/38nYGS
octave
//ideone.com/g7FrVu
ruby
//ideone.com/YyFXWh
*/
class Ideone
{
public static void main
(String[] args
) {
hoge(10, 4);
}
static void hoge(int x, int y)
{
long[] n = calc(x, y);
for(int i = 0; i < n.length; i++)
System.
out.
printf("%d\t%d%n", i, n
[i
]); }
static long[] calc(int x, int y)
{
long[] ary = new long[x];
while (--y > 0)
{
long[] next = new long[ary.length + x - 1];
long num = 0;
for (int i = 0; i < next.length; i++)
{
long add = i < ary.length ? ary[i] : 0;
long sub = i - x >= 0 ? ary[i - x] : 0;
num += add - sub;
next[i] = num;
}
ary = next;
}
return ary;
}
}
aW1wb3J0IGphdmEudXRpbC5BcnJheXM7CgovKgrjg5fjg63jgrDjg6njg5/jg7PjgrDjga7jgYrpoYzjgrnjg6wgUGFydDE1IAovL21ldml1cy41Y2gubmV0L3Rlc3QvcmVhZC5jZ2kvdGVjaC8xNTY0MzEwMzk3Lzc0NAo3NDQg5ZCN5YmN77ya44OH44OV44Kp44Or44OI44Gu5ZCN54Sh44GX44GV44KTW3NhZ2VdIOaKleeov+aXpe+8mjIwMTkvMTAvMTEo6YeRKSAyMTo1NTo1NC42MSBJRDp6S2FDM3h2MArjgYrpoYzvvJow772eOTk5OeOBruaVtOaVsOOBq+OBpOOBhOOBpuaVsOWtl+WSjOOCkuaxguOCgeOAgeaVsOWtl+WSjOOBrumgu+W6puOCkumbhuioiOOBm+OCiAoKb2NhbWwKLy9pZGVvbmUuY29tL0FqY0dncAoKYwovL2lkZW9uZS5jb20vMzhuWUdTCgpvY3RhdmUKLy9pZGVvbmUuY29tL2c3RnJWdQoKcnVieQovL2lkZW9uZS5jb20vWXlGWFdoCiovCmNsYXNzIElkZW9uZQp7CiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKQogICAgewoJCWhvZ2UoMTAsIDQpOwogICAgfQogICAgCiAgICBzdGF0aWMgdm9pZCBob2dlKGludCB4LCBpbnQgeSkKICAgIHsKCSAgICBsb25nW10gbiA9IGNhbGMoeCwgeSk7CiAgICAgICAgZm9yKGludCBpID0gMDsgaSA8IG4ubGVuZ3RoOyBpKyspCiAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRmKCIlZFx0JWQlbiIsIGksIG5baV0pOwogICAgfQogCiAgICBzdGF0aWMgbG9uZ1tdIGNhbGMoaW50IHgsIGludCB5KQogICAgewogICAgICAgIGxvbmdbXSBhcnkgPSBuZXcgbG9uZ1t4XTsKICAgICAgICBBcnJheXMuZmlsbChhcnksIDEpOwogCiAgICAgICAgd2hpbGUgKC0teSA+IDApCiAgICAgICAgewogICAgICAgICAgICBsb25nW10gbmV4dCA9IG5ldyBsb25nW2FyeS5sZW5ndGggKyB4IC0gMV07CiAgICAgICAgICAgIGxvbmcgbnVtID0gMDsKICAgICAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuZXh0Lmxlbmd0aDsgaSsrKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBsb25nIGFkZCA9IGkgPCBhcnkubGVuZ3RoID8gYXJ5W2ldIDogMDsKICAgICAgICAgICAgICAgIGxvbmcgc3ViID0gaSAtIHggPj0gMCA/IGFyeVtpIC0geF0gOiAwOwogICAgICAgICAgICAgICAgbnVtICs9IGFkZCAtIHN1YjsKICAgICAgICAgICAgICAgIG5leHRbaV0gPSBudW07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYXJ5ID0gbmV4dDsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGFyeTsKICAgIH0KfQ==