結果

問題 No.1946 ロッカーの問題
ユーザー tentententen
提出日時 2022-05-23 17:37:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 736 ms / 3,000 ms
コード長 1,513 bytes
コンパイル時間 3,266 ms
コンパイル使用メモリ 77,096 KB
実行使用メモリ 61,520 KB
最終ジャッジ日時 2023-10-20 17:38:20
合計ジャッジ時間 8,051 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
53,484 KB
testcase_01 AC 52 ms
53,484 KB
testcase_02 AC 54 ms
53,488 KB
testcase_03 AC 658 ms
61,364 KB
testcase_04 AC 54 ms
53,492 KB
testcase_05 AC 119 ms
56,328 KB
testcase_06 AC 100 ms
55,436 KB
testcase_07 AC 114 ms
56,420 KB
testcase_08 AC 305 ms
59,380 KB
testcase_09 AC 575 ms
61,520 KB
testcase_10 AC 549 ms
60,896 KB
testcase_11 AC 88 ms
55,112 KB
testcase_12 AC 213 ms
57,524 KB
testcase_13 AC 50 ms
53,484 KB
testcase_14 AC 48 ms
53,488 KB
testcase_15 AC 49 ms
53,484 KB
testcase_16 AC 49 ms
53,484 KB
testcase_17 AC 397 ms
59,432 KB
testcase_18 AC 736 ms
59,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        boolean[] isOpen = new boolean[n + 1];
        for (int i = 0; i < m; i++) {
            isOpen[sc.nextInt()] = true;
        }
        int count = 0;
        for (int i = n; i > 0; i--) {
            if (!isOpen[i]) {
                count++;
                continue;
            }
            for (int j = 1; j <= Math.sqrt(i); j++) {
                if (i % j == 0) {
                    isOpen[j] ^= true;
                    if (j * j < i) {
                        isOpen[i / j] ^= true;
                    }
                }
            }
        }
        System.out.println(count);
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0