September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
100
Task/Paraffins/FreeBASIC/paraffins.freebasic
Normal file
100
Task/Paraffins/FreeBASIC/paraffins.freebasic
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
' version 31-12-2016
|
||||
' compile with: fbc -s console
|
||||
' uses gmp, translation from pascal
|
||||
|
||||
#Include Once "gmp.bi"
|
||||
|
||||
Const As Integer max_n = 500, branch = 4
|
||||
|
||||
Dim Shared As mpz_ptr rooted(), unrooted(), c()
|
||||
Dim Shared As mpz_ptr cnt, tmp
|
||||
|
||||
Sub tree(br As UInteger, n As UInteger, l As UInteger, sum As UInteger, cnt As mpz_ptr)
|
||||
|
||||
Dim As UInteger b, m
|
||||
|
||||
For b = br +1 To branch
|
||||
sum = sum + n
|
||||
If sum > max_n Then Return
|
||||
|
||||
' prevent unneeded long math
|
||||
If (l * 2 >= sum) And (b >= branch) Then Return
|
||||
|
||||
If b = (br +1) Then
|
||||
mpz_mul(c(br), rooted(n), cnt)
|
||||
Else
|
||||
mpz_add_ui(tmp, rooted(n), b - br -1)
|
||||
mpz_mul(c(br), c(br), tmp)
|
||||
mpz_divexact_ui(c(br), c(br), b - br)
|
||||
End If
|
||||
|
||||
If l * 2 < sum Then
|
||||
mpz_add(unrooted(sum), unrooted(sum), c(br))
|
||||
End If
|
||||
If b < branch Then
|
||||
mpz_add(rooted(sum), rooted(sum), c(br))
|
||||
For m = n -1 To 1 Step -1
|
||||
tree(b, m, l, sum, c(br))
|
||||
Next
|
||||
End If
|
||||
Next
|
||||
|
||||
End Sub
|
||||
|
||||
Sub bicenter(s As UInteger)
|
||||
If (s And 1) = 1 Then Return
|
||||
mpz_add_ui(tmp, rooted(s \ 2), 1)
|
||||
mpz_mul(tmp, rooted(s \ 2), tmp)
|
||||
mpz_tdiv_q_2exp(tmp, tmp, 1)
|
||||
mpz_add(unrooted(s), unrooted(s), tmp)
|
||||
End Sub
|
||||
|
||||
' ------=< MAIN >=------
|
||||
|
||||
Dim As UInteger n, sum
|
||||
Dim As ZString Ptr ans
|
||||
|
||||
ReDim rooted(max_n), unrooted(max_n)
|
||||
For n = 0 To max_n
|
||||
rooted(n) = Allocate(Len(__mpz_struct)) : Mpz_init( rooted(n))
|
||||
unrooted(n) = Allocate(Len(__mpz_struct)) : Mpz_init(unrooted(n))
|
||||
Next
|
||||
For n = 0 To 1
|
||||
mpz_set_ui( rooted(n), 1)
|
||||
mpz_set_ui(unrooted(n), 1)
|
||||
Next
|
||||
|
||||
ReDim c(branch -1)
|
||||
For n = 0 To branch -1
|
||||
c(n) = Allocate(Len(__mpz_struct)) : Mpz_init(c(n))
|
||||
Next
|
||||
|
||||
cnt = Allocate(Len(__mpz_struct)) : Mpz_init_set_ui(cnt, 1)
|
||||
tmp = Allocate(Len(__mpz_struct)) : Mpz_init(tmp)
|
||||
|
||||
sum = 1
|
||||
For n = 1 To max_n
|
||||
tree(0, n, n, sum, cnt)
|
||||
bicenter(n)
|
||||
'gmp_printf("%d: %Zd"+Chr(13)+Chr(10), n, unrooted(n))
|
||||
ans = Mpz_get_str (0, 10, unrooted(n))
|
||||
Print Using "###: "; n; : Print *ans
|
||||
Next
|
||||
|
||||
For n = 0 To max_n
|
||||
mpz_Clear( rooted(n))
|
||||
mpz_Clear(unrooted(n))
|
||||
Next
|
||||
|
||||
For n = 0 To branch -1
|
||||
mpz_clear(c(n))
|
||||
Next
|
||||
|
||||
mpz_clear(cnt)
|
||||
mpz_clear(tmp)
|
||||
|
||||
' empty keyboard buffer
|
||||
While Inkey <> "" : Wend
|
||||
Print : Print "hit any key to end program"
|
||||
Sleep
|
||||
End
|
||||
48
Task/Paraffins/Kotlin/paraffins.kotlin
Normal file
48
Task/Paraffins/Kotlin/paraffins.kotlin
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
// version 1.1.4-3
|
||||
|
||||
import java.math.BigInteger
|
||||
|
||||
const val MAX_N = 250
|
||||
const val BRANCHES = 4
|
||||
|
||||
val rooted = Array(MAX_N + 1) { if (it < 2) BigInteger.ONE else BigInteger.ZERO }
|
||||
val unrooted = Array(MAX_N + 1) { if (it < 2) BigInteger.ONE else BigInteger.ZERO }
|
||||
val c = Array(BRANCHES) { BigInteger.ZERO }
|
||||
|
||||
fun tree(br: Int, n: Int, l: Int, s: Int, cnt: BigInteger) {
|
||||
var sum = s
|
||||
for (b in (br + 1)..BRANCHES) {
|
||||
sum += n
|
||||
if (sum > MAX_N || (l * 2 >= sum && b >= BRANCHES)) return
|
||||
|
||||
var tmp = rooted[n]
|
||||
if (b == br + 1) {
|
||||
c[br] = tmp * cnt
|
||||
}
|
||||
else {
|
||||
val diff = (b - br).toLong()
|
||||
c[br] *= tmp + BigInteger.valueOf(diff - 1L)
|
||||
c[br] /= BigInteger.valueOf(diff)
|
||||
}
|
||||
|
||||
if (l * 2 < sum) unrooted[sum] += c[br]
|
||||
if (b < BRANCHES) rooted[sum] += c[br]
|
||||
for (m in n - 1 downTo 1) tree(b, m, l, sum, c[br])
|
||||
}
|
||||
}
|
||||
|
||||
fun bicenter(s: Int) {
|
||||
if ((s and 1) == 0) {
|
||||
var tmp = rooted[s / 2]
|
||||
tmp *= tmp + BigInteger.ONE
|
||||
unrooted[s] += tmp.shiftRight(1)
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
for (n in 1..MAX_N) {
|
||||
tree(0, n, n, 1, BigInteger.ONE)
|
||||
bicenter(n)
|
||||
println("$n: ${unrooted[n]}")
|
||||
}
|
||||
}
|
||||
15
Task/Paraffins/PARI-GP/paraffins-1.pari
Normal file
15
Task/Paraffins/PARI-GP/paraffins-1.pari
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
paraffin(p) =
|
||||
{
|
||||
local (P = p+1, R, U = R = Vec([1,1], P));
|
||||
|
||||
for (n = 1, p,
|
||||
((B,n,C,S,l=n) -> my(b,c,i,s);
|
||||
for (b = 1, 4-B,
|
||||
if ((s = S + b * n) < P,
|
||||
c = R[n+1] * C * prod(i = 1, b-1, (R[n+1]+i)/(i+1));
|
||||
if (l+l < s, U[s+1] += c);
|
||||
if (B+b < 4, R[s+1] += c; i = n; while (i--, self()(B+b, i, c, s, l)))))
|
||||
)(0,n,1,1);
|
||||
if (n % 2,, U[n+1] += R[n/2+1] * (R[n/2+1]+1)/2);
|
||||
print([n, U[n+1]]))
|
||||
}
|
||||
19
Task/Paraffins/PARI-GP/paraffins-2.pari
Normal file
19
Task/Paraffins/PARI-GP/paraffins-2.pari
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
iso(B,n,C,S,l=n) =
|
||||
{
|
||||
my (b,c,i,s);
|
||||
|
||||
for (b = 1, 4-B,
|
||||
if ((s = S + b * n) < P,
|
||||
c = R[n+1] * C * prod(i = 1, b-1, (R[n+1]+i)/(i+1));
|
||||
if (l+l < s, U[s+1] += c);
|
||||
if (B+b < 4, R[s+1] += c; i = n; while (i--, iso(B+b, i, c, s, l)))))
|
||||
}
|
||||
|
||||
paraffin(p) =
|
||||
{
|
||||
local (P = p+1, R, U = R = Vec([1,1], P));
|
||||
|
||||
for (n = 1, p, iso(0, n, 1, 1);
|
||||
if (n % 2,, U[n+1] += R[n/2+1] * (R[n/2+1]+1)/2);
|
||||
print([n, U[n+1]]))
|
||||
}
|
||||
35
Task/Paraffins/Zkl/paraffins.zkl
Normal file
35
Task/Paraffins/Zkl/paraffins.zkl
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
var BN=Import("zklBigNum");
|
||||
|
||||
const nMax=100, nBranches=4;
|
||||
|
||||
var rooted =(nMax+1).pump(List.createLong(nMax+1).write,BN.fp(0)),
|
||||
unrooted=(nMax+1).pump(List.createLong(nMax+1).write,BN.fp(0));
|
||||
rooted[0]=BN(1); rooted[1]=BN(1); unrooted[0]=BN(1); unrooted[1]=BN(1);
|
||||
|
||||
fcn tree(br,n,l,inSum,cnt){
|
||||
var c=(nBranches).pump(List().write,0); // happens only once
|
||||
|
||||
sum := inSum;
|
||||
foreach b in ([br + 1 .. nBranches]){
|
||||
sum += n;
|
||||
if (sum > nMax or (l * 2 >= sum and b >= nBranches)) return();
|
||||
if (b == br + 1) c[br] = rooted[n] * cnt; // -->BigInt
|
||||
else{
|
||||
c[br].mul(rooted[n] + b - br - 1);
|
||||
c[br].div(b - br);
|
||||
}
|
||||
if (l * 2 < sum) unrooted[sum].add(c[br]);
|
||||
if (b < nBranches) rooted[sum].add(c[br]);
|
||||
foreach m in ([n-1 .. 1,-1]) { tree(b, m, l, sum, c[br]); }
|
||||
}
|
||||
}
|
||||
|
||||
fcn bicenter(s){
|
||||
if (s.isEven) unrooted[s].add(rooted[s / 2] * (rooted[s / 2] + 1) / 2);
|
||||
}
|
||||
|
||||
foreach n in ([1 .. nMax]){
|
||||
tree(0, n, n, 1, BN(1));
|
||||
bicenter(n);
|
||||
println(n, ": ", unrooted[n]);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue