結果

問題 No.64 XORフィボナッチ数列
ユーザー rocoderrocoder
提出日時 2017-08-09 08:53:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 33 ms / 5,000 ms
コード長 1,600 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-20 07:25:06
合計ジャッジ時間 1,087 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
10,880 KB
testcase_01 AC 33 ms
10,880 KB
testcase_02 AC 32 ms
10,880 KB
testcase_03 AC 30 ms
10,880 KB
testcase_04 AC 29 ms
11,008 KB
testcase_05 AC 29 ms
11,008 KB
testcase_06 AC 29 ms
10,880 KB
testcase_07 AC 29 ms
10,880 KB
testcase_08 AC 29 ms
11,008 KB
testcase_09 AC 30 ms
10,880 KB
testcase_10 AC 29 ms
11,008 KB
testcase_11 AC 30 ms
11,008 KB
testcase_12 AC 29 ms
10,880 KB
testcase_13 AC 29 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#r code goes here
#xorf
import math
def tw(n):
    t=1
    k=1
    while t<=n//2:
        t*=2
        k+=1
 #       print (k)
    tt=[]
    while n>0:    
        q=n//t
 #       print (n)
        tt.append(q)
 #       print (tt)
        q*=t
        t//=2
        n-=q
    #    print (n)
        k-=1
  #  print (k)
    while k>0:
        tt.append(0)
#        print (tt)
        k-=1
    return tt
def twe(li):
    en=0
    t1=1
    i=len(li)-1
    while i>=0:
        en+=t1*li[i]
        t1*=2
        i-=1
    return en
def xorf (l0,l1,N):
    lel0=len(l0)
 #   lel1=len(l1)
  #  if lel0>lel1:
   #     lll=lel0
    #    lls=lel1
   # else:
    #    lll=lel1
     #   lls=lel0
#    print(l1)
    l2=[0]*len(l0)
    R=N%3
    for i in range (lel0):
        a=l0[lel0-i-1]
#        print("a")
        b=l1[lel0-i-1]
        if a==0 and b==0:
            c=0
        elif a==0 and b==1:
            if R==0:
                c=0
            else:
                c=1
        elif a==1 and b==0:
            if R==1:
                c=0
            else:
                c=1
        else:
            if R==2:
                c=0
            else:
                c=1
        l2[lel0-i-1]=c
    return l2
F0,F1,N=(int(i) for i in input().split())
#print (F0)
if N==0:
    print (F0)
#    print(int(F0))  
elif N==1:
    print(F1)
else:
    F0=tw(F0)
    F1=tw(F1)
 #   print(F0)
   # print(F1)
    Di=len(F0)-len(F1)
    if Di>0:
        Dk=[0]*Di
        F1=Dk+F1
    elif Di<0:
        Di*=-1
        Dk=[0]*Di
        F0=Dk+F0
 #   print(F0)
    F2=xorf(F0,F1,N)
 #   print(F2)
    print(twe(F2))
0