mersenneforum.org  

Go Back   mersenneforum.org > Fun Stuff > Puzzles

Reply
 
Thread Tools
Old 2022-09-03, 11:47   #12
Dieter
 
Oct 2017

2×5×13 Posts
Default

Quote:
Originally Posted by KangJ View Post
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
Dieter is offline   Reply With Quote
Old 2022-09-05, 17:50   #13
KangJ
 
Jul 2015

2×7 Posts
Default

Quote:
Originally Posted by SmartMersenne View Post
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.
KangJ is offline   Reply With Quote
Reply

Thread Tools


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

All times are UTC. The time now is 06:44.


Sun Oct 2 06:44:27 UTC 2022 up 45 days, 4:13, 0 users, load averages: 1.36, 1.18, 1.09

Powered by vBulletin® Version 3.8.11
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.

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