mersenneforum.org August 2022
 User Name Remember Me? Password
 Register FAQ Search Today's Posts Mark Forums Read

2022-09-03, 11:47   #12
Dieter

Oct 2017

2·5·13 Posts

Quote:
 Originally Posted by KangJ The time complexity can be O(log n). So you can easily get the answer even for n = 2^100000. (The number is 2703445608 for n = 2^100000, and only 12 seconds elapsed in my code.)
I can confirm this value, but my code needs about 2 hours.

0,072 seconds for the transition from 2^n to 2^(n+1)

Last fiddled with by Dieter on 2022-09-03 at 11:49

2022-09-05, 17:50   #13
KangJ

Jul 2015

2×7 Posts

Quote:
 Originally Posted by SmartMersenne I hope that you can show us how after the answer is published.
Code:
D = 3141592653

# dance arrangement can be classified into 7 cases
# by [1 / 11 / 12 / 13 / 22 / 23 / 33]

# which means
# one dancer with 1 unit of time
# two dancer with 1,1 units of time
# two dancer with 1,2 units of time
# two dancer with 1,3 units of time
# two dancer with 2,2 units of time
# two dancer with 2,3 units of time
# two dancer with 3,3 units of time

# from a case to another case,
# the number of possible arrangement can constitute a matrix
ori_M = [[3, 2, 2, 2, 2, 2, 2],
[6, 0, 0, 0, 0, 0, 0],
[0, 4, 2, 2, 0, 0, 0],
[0, 0, 2, 0, 4, 2, 0],
[0, 1, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0]]

def count(N):
ori_N = N
N = N - 1

# number to binary
N_binary = []
while N > 0:
if N % 2 == 0:
N_binary.append(0)
else:
N_binary.append(1)
N = N // 2

# initial matrix
if len(N_binary) == 0:
M = [[1, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 1]]
else:
M = [[3, 2, 2, 2, 2, 2, 2],
[6, 0, 0, 0, 0, 0, 0],
[0, 4, 2, 2, 0, 0, 0],
[0, 0, 2, 0, 4, 2, 0],
[0, 1, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0]]

# calculate M^N
for i in range(len(N_binary)-2, -1, -1):
next_M = [[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0]]

for j in range(7):
for k in range(7):
for l in range(7):
next_M[j][k] += M[j][l] * M[l][k]
for j in range(7):
for k in range(7):
M[j][k] = next_M[j][k] % D

if N_binary[i] == 1:
next_M = [[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0]]

for j in range(7):
for k in range(7):
for l in range(7):
next_M[j][k] += M[j][l] * ori_M[l][k]
for j in range(7):
for k in range(7):
M[j][k] = next_M[j][k] % D

# number of arrangement = M^N * A
A = [4, 12, 0, 0, 0, 0, 0]
next_A = [0, 0, 0, 0, 0, 0, 0]
for i in range(7):
for j in range(7):
next_A[i] += A[j] * M[i][j]
for i in range(7):
next_A[i] = next_A[i] % D

# sum of all cases
S = 0
for i in range(7):
S += next_A[i]

print(S % D)

count(2**24)
count(2**256)
A simple python code.

 Similar Threads Thread Thread Starter Forum Replies Last Post tgan Puzzles 3 2021-09-06 11:24 Xyzzy Puzzles 3 2020-08-29 08:33 Xyzzy Puzzles 20 2019-09-09 09:40 Xyzzy Puzzles 2 2014-11-02 19:04 Wacky NFSNET Discussion 0 2007-08-09 02:32

All times are UTC. The time now is 23:22.

Sat Sep 24 23:22:31 UTC 2022 up 37 days, 20:51, 0 users, load averages: 1.35, 1.08, 0.97

Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.

≠ ± ∓ ÷ × · − √ ‰ ⊗ ⊕ ⊖ ⊘ ⊙ ≤ ≥ ≦ ≧ ≨ ≩ ≺ ≻ ≼ ≽ ⊏ ⊐ ⊑ ⊒ ² ³ °
∠ ∟ ° ≅ ~ ‖ ⟂ ⫛
≡ ≜ ≈ ∝ ∞ ≪ ≫ ⌊⌋ ⌈⌉ ∘ ∏ ∐ ∑ ∧ ∨ ∩ ∪ ⨀ ⊕ ⊗ 𝖕 𝖖 𝖗 ⊲ ⊳
∅ ∖ ∁ ↦ ↣ ∩ ∪ ⊆ ⊂ ⊄ ⊊ ⊇ ⊃ ⊅ ⊋ ⊖ ∈ ∉ ∋ ∌ ℕ ℤ ℚ ℝ ℂ ℵ ℶ ℷ ℸ 𝓟
¬ ∨ ∧ ⊕ → ← ⇒ ⇐ ⇔ ∀ ∃ ∄ ∴ ∵ ⊤ ⊥ ⊢ ⊨ ⫤ ⊣ … ⋯ ⋮ ⋰ ⋱
∫ ∬ ∭ ∮ ∯ ∰ ∇ ∆ δ ∂ ℱ ℒ ℓ
𝛢𝛼 𝛣𝛽 𝛤𝛾 𝛥𝛿 𝛦𝜀𝜖 𝛧𝜁 𝛨𝜂 𝛩𝜃𝜗 𝛪𝜄 𝛫𝜅 𝛬𝜆 𝛭𝜇 𝛮𝜈 𝛯𝜉 𝛰𝜊 𝛱𝜋 𝛲𝜌 𝛴𝜎𝜍 𝛵𝜏 𝛶𝜐 𝛷𝜙𝜑 𝛸𝜒 𝛹𝜓 𝛺𝜔