結果

問題 No.1871 divisXor
ユーザー ygd.ygd.
提出日時 2022-03-17 21:12:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 2,377 bytes
コンパイル時間 187 ms
コンパイル使用メモリ 13,056 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-09 19:57:15
合計ジャッジ時間 7,592 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
11,008 KB
testcase_01 AC 27 ms
11,008 KB
testcase_02 AC 528 ms
11,136 KB
testcase_03 AC 457 ms
11,008 KB
testcase_04 AC 108 ms
11,136 KB
testcase_05 AC 124 ms
11,008 KB
testcase_06 AC 106 ms
11,136 KB
testcase_07 AC 188 ms
11,136 KB
testcase_08 AC 446 ms
11,136 KB
testcase_09 AC 165 ms
11,008 KB
testcase_10 AC 129 ms
11,136 KB
testcase_11 AC 203 ms
11,008 KB
testcase_12 AC 108 ms
11,008 KB
testcase_13 AC 80 ms
11,008 KB
testcase_14 AC 151 ms
11,136 KB
testcase_15 AC 151 ms
11,008 KB
testcase_16 AC 210 ms
11,008 KB
testcase_17 AC 214 ms
11,136 KB
testcase_18 AC 166 ms
11,136 KB
testcase_19 AC 191 ms
11,008 KB
testcase_20 AC 192 ms
11,008 KB
testcase_21 AC 168 ms
11,136 KB
testcase_22 AC 25 ms
11,136 KB
testcase_23 AC 27 ms
11,008 KB
testcase_24 AC 26 ms
11,008 KB
testcase_25 WA -
testcase_26 AC 382 ms
11,136 KB
testcase_27 AC 387 ms
11,136 KB
testcase_28 AC 198 ms
11,136 KB
testcase_29 WA -
testcase_30 AC 140 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = sys.stdin.readline
#input = sys.stdin.buffer.readline #文字列はダメ
#sys.setrecursionlimit(1000000)
#import bisect
#import itertools
#import random
#from heapq import heapify, heappop, heappush
#from collections import defaultdict 
#from collections import deque
#import copy
#import math
#from functools import lru_cache
#@lru_cache(maxsize=None)
#MOD = pow(10,9) + 7
#MOD = 998244353
#dx = [1,0,-1,0]
#dy = [0,1,0,-1]
#dx8 = [1,1,0,-1,-1,-1,0,1]
#dy8 = [0,1,1,1,0,-1,-1,-1]

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

def f(x):
    L = make_divisors(x)
    return sum(L)


def f2(x):
    return pow(2,x)

def prime_factorize(n):
    ret = []
    #if n == 1:
    #    ret.append((1,1))
    #    return ret
    cnt = 0
    while n % 2 == 0:
        cnt += 1
        n //= 2
    if cnt > 0:
        ret.append((2,cnt))
    i = 3
    while i * i <= n:
        cnt = 0
        while n % i == 0:
            cnt += 1
            n //= i
        else:
            if cnt != 0: #cnt==0の時は追加しない
                ret.append((i,cnt))
            i += 2
    if n != 1:
        ret.append((n,1))
    return ret #(素因数、何乗)

def check(x):
    L = prime_factorize(x)
    if len(L) == 1 and L[0][1] == 1:
        return True
    else:
        return False

def main():
    N = int(input())
    if N == 0:
        print(-1);exit()
    if N == 1:
        print(1)
        print(1);exit()
    if N == 2:
        ans = [1,1]
        print(2)
        print(*ans);exit()
    for i in range(20):
        temp = pow(2,i+1) - 1
        if temp == N:
            print(1)
            print(pow(2,i))
            exit()

    X = N-1
    while True:
        if check(X):
            break
        else:
            X += 1
    N ^= (X+1)
    #print("N",N,"X",X)
    L = []
    P = 15
    pre = 0
    for i in reversed(range(P)):
        if (N>>i)&1 == pre: continue
        L.append(i)
        pre = pre^1
    #print(L)
    ans = [f2(x) for x in L] + [X]
    print(len(ans))
    print(*ans)
    exit()

    v = 0
    for a in ans:
        v ^= f(a)
    print(v)



if __name__ == '__main__':
    main()
0