結果
| 問題 | 
                            No.1946 ロッカーの問題
                             | 
                    
| コンテスト | |
| ユーザー | 
                             ygd.
                         | 
                    
| 提出日時 | 2022-05-21 11:51:54 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 2,564 ms / 3,000 ms | 
| コード長 | 1,522 bytes | 
| コンパイル時間 | 287 ms | 
| コンパイル使用メモリ | 82,048 KB | 
| 実行使用メモリ | 109,824 KB | 
| 最終ジャッジ日時 | 2024-09-20 11:25:48 | 
| 合計ジャッジ時間 | 22,714 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 19 | 
ソースコード
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 main():
    N,M = map(int,input().split())
    A = list(map(int,input().split()))
    #0:閉, 1:開
    state = [0]*(N+1)
    for a in A:
        state[a] = 1
    ideal = [0]*(N+1)
    for v in range(1,N+1):
        L = make_divisors(v)
        for p in L:
            ideal[p] ^= 1
    
    ans = 0
    for v in reversed(range(1,N+1)):
        L = make_divisors(v)
        if state[v] != ideal[v]:
            #さぼった
            ans += 1
            for p in L:
                ideal[p] ^= 1
        else:
            for p in L:
                ideal[p] ^= 1
                state[p] ^= 1
        #print("idea",ideal)
        #print("now",state)
    print(ans)
        
if __name__ == '__main__':
    main()
            
            
            
        
            
ygd.